blob: 4016bdc163408f5396d96135d1ea8180fc08084b [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
Akron386f1222022-12-21 16:26:11 +0100727 expect(matchObj.panel.type).toEqual('match');
728
Akron7f9a6a32018-07-18 15:05:23 +0200729 // now
730 var infotable = matchElement.children[1];
731 expect(infotable.tagName).toEqual('DIV');
732
733 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
734
735 expect(infotable.firstChild.firstChild.firstChild.classList.contains('matchtable')).toBeTruthy();
736
737 // expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
738 });
739
Akron158fce12019-12-17 14:43:29 +0100740 it('should parse into a table view with non-verbal elements (sync)', function () {
741 var matchElement = matchElementFactory();
742 expect(matchElement.tagName).toEqual('LI');
743 });
744
Akronb7749052022-07-22 18:03:26 +0200745 it('should parse into a table with non-latin characters', function () {
746 var matchElement = matchElementFactory();
747 expect(matchElement.tagName).toEqual('LI');
748
749 // Match
750 expect(matchElement.children[0].tagName).toEqual('DIV');
751
752 // snippet
753 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
754 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
755 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
756
757 // reference
758 expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
759 expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
760
761 // not yet
762 expect(matchElement.children[0].children[1]).toBe(undefined);
763
764 /*
765 var info = matchClass.create(matchElement).info();
766 info.showTable();
767 */
768 var matchObj = matchClass.create(matchElement);
769 matchObj.open();
770
771 // Match
772 expect(matchElement.children[0].tagName).toEqual('DIV');
773
774 // snippet
775 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
776
777 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
778
779 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
780
781 // reference
782
783 expect(matchElement.children[2].classList.contains('ref')).toBeTruthy();
784 expect(matchElement.children[2].childNodes[1].nodeValue).toEqual('me');
785
786 // Add table
787 matchObj.panel.addTable();
788
789 // now
790 var infotable = matchElement.children[1];
791 expect(infotable.tagName).toEqual('DIV');
792
793 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
794
795 expect(infotable.firstChild.firstChild.firstChild.classList.contains('matchtable')).toBeTruthy();
796
797 // expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
798 });
799
800 it('should parse into a table view with all non-latin characters (sync)', function () {
801
802 // Override getMatchInfo API call
803 KorAP.API.getMatchInfo = function (x, param, cb) {
804 cb({ "snippet": snippetDiffToken });
805 };
806
807 var matchElement = matchElementFactory();
808 expect(matchElement.tagName).toEqual('LI');
809
810 // Match
811 expect(matchElement.children[0].tagName).toEqual('DIV');
812
813 var matchObj = matchClass.create(matchElement);
814 matchObj.open();
815
816 // Match
817 expect(matchElement.children[0].tagName).toEqual('DIV');
818
819 // snippet
820 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
821
822 // Add table
823 matchObj.panel.addTable();
824
825 // now
826 var infotable = matchElement.children[1];
827 expect(infotable.tagName).toEqual('DIV');
828
829 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
830
831 expect(infotable.firstChild.firstChild.firstChild.classList.contains('matchtable')).toBeTruthy();
832
833 let matchTable = infotable.firstChild.firstChild.firstChild;
834 expect(matchTable.querySelectorAll("th:not(.cutted).no-anno")[0].textContent).toEqual('Außerdem ');
835 expect(matchTable.getElementsByTagName('TH')[4].textContent).toEqual('Диес');
836 expect(matchTable.querySelectorAll("tbody tr:nth-child(1) td")[0].classList.contains('not-empty')).toBeFalsy();
837 expect(matchTable.querySelectorAll("tbody tr:nth-child(1) td")[1].classList.contains('not-empty')).toBeFalsy();
838 expect(matchTable.querySelectorAll("tbody tr:nth-child(1) td")[2].classList.contains('not-empty')).toBeFalsy();
839 expect(matchTable.querySelectorAll("tbody tr:nth-child(5) td")[0].classList.contains('not-empty')).toBeFalsy();
840 expect(matchTable.querySelectorAll("tbody tr:nth-child(5) td")[1].classList.contains('not-empty')).toBeFalsy();
841 expect(matchTable.querySelectorAll("tbody tr:nth-child(5) td")[2].classList.contains('not-empty')).toBeTruthy();
842 });
843
Nils Diewald58141332015-04-07 16:18:45 +0000844 });
Nils Diewalda297f062015-04-02 00:23:46 +0000845
Akron7f9a6a32018-07-18 15:05:23 +0200846 describe('KorAP.RelationsView', function () {
Akrond8692de2018-07-26 13:06:01 +0200847 beforeAll(beforeAllFunc);
848 afterAll(afterAllFunc);
849
Nils Diewald7c8ced22015-04-15 19:21:00 +0000850 var tree;
Nils Diewalda297f062015-04-02 00:23:46 +0000851
Nils Diewald7c8ced22015-04-15 19:21:00 +0000852 it('should be rendered async 1', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200853 var matchObj = matchClass.create(match);
854 var relObj = relClass.create(matchObj);
855 expect(relObj).toBeTruthy();
856 relObj.getData(undefined, undefined, "spans", function (y) {
Akron671fdb92017-09-12 18:09:46 +0200857 tree = y;
858 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000859 });
860 });
Nils Diewalda297f062015-04-02 00:23:46 +0000861
Nils Diewald7c8ced22015-04-15 19:21:00 +0000862 it('should be rendered async 2', function () {
Akron7f9a6a32018-07-18 15:05:23 +0200863 expect(tree).toBeTruthy();
864 expect(tree.nodes()).toEqual(49);
865
Nils Diewald7c8ced22015-04-15 19:21:00 +0000866 var e = tree.element();
867 expect(e.nodeName).toEqual('svg');
868 expect(e.getElementsByTagName('g').length).toEqual(48);
Nils Diewald58141332015-04-07 16:18:45 +0000869 });
Akron7f9a6a32018-07-18 15:05:23 +0200870
871
872 it('should add a tree view async 2', function () {
873 var matchElement = matchElementFactory();
874 var matchObj = matchClass.create(matchElement);
875 matchObj.open();
876 matchObj.panel.addTree('mate', 'beebop', 'spans', function () {
877 done();
878 });
879
880 // With added tree
881 var tree = matchElement.children[1].firstChild.firstChild.firstChild;
882 expect(tree.tagName).toEqual('DIV');
883 expect(tree.classList.contains('matchtree')).toBeTruthy();
884 expect(tree.children[0].tagName).toEqual('H6');
885 expect(tree.children[0].children[0].tagName).toEqual('SPAN');
886 expect(tree.children[0].children[0].firstChild.nodeValue).toEqual('mate');
887 expect(tree.children[0].children[1].tagName).toEqual('SPAN');
888 expect(tree.children[0].children[1].firstChild.nodeValue).toEqual('beebop');
889
890 expect(tree.children[1].tagName).toEqual('DIV');
891 });
892
Akron3bdac532019-03-04 13:24:43 +0100893 it('should make the tree downloadable', function () {
894 var treeClass = matchHierClass.create(treeSnippetHierarchy);
895 var treeElement = treeClass.element();
896 expect(treeElement.tagName).toEqual("svg");
897
898 var base64 = treeClass.toBase64();
899 var str = atob(base64);
900 expect(str).toMatch(new RegExp('<defs><style>path'));
901 expect(str).not.toMatch(new RegExp('&nbsp;'));
902 expect(str).toMatch(new RegExp('&amp;'));
903 });
Nils Diewald58141332015-04-07 16:18:45 +0000904 });
Nils Diewalda297f062015-04-02 00:23:46 +0000905
Nils Diewald7c8ced22015-04-15 19:21:00 +0000906
907 describe('KorAP.MatchTreeItem', function () {
Akrond8692de2018-07-26 13:06:01 +0200908 beforeAll(beforeAllFunc);
909 afterAll(afterAllFunc);
910
Nils Diewald7c8ced22015-04-15 19:21:00 +0000911 it('should be initializable', function () {
912 var mi = matchTreeItemClass.create(['cnx/c', 'cnx', 'c'])
913 expect(mi.element().firstChild.nodeValue).toEqual('cnx/c');
914 expect(mi.lcField()).toEqual(' cnx/c');
915 expect(mi.foundry()).toEqual('cnx');
916 expect(mi.layer()).toEqual('c');
917 });
Nils Diewalda297f062015-04-02 00:23:46 +0000918 });
Nils Diewalda297f062015-04-02 00:23:46 +0000919
920
Akron671fdb92017-09-12 18:09:46 +0200921 describe('KorAP.MatchRelation', function () {
Akrond8692de2018-07-26 13:06:01 +0200922 beforeAll(beforeAllFunc);
923 afterAll(afterAllFunc);
Akron671fdb92017-09-12 18:09:46 +0200924
925 var relExample = "<span class=\"context-left\"></span>" +
926 "<span class=\"match\">" +
927 " <span xml:id=\"token-GOE/AGA/01784-p199\">" +
928 " <span xlink:title=\"malt/d:ADV\" " +
929 " xlink:type=\"simple\" " +
930 " xlink:href=\"#token-GOE/AGA/01784-p199\">dann</span>" +
931 " </span>" +
932 " zog " +
933 " <span xlink:title=\"malt/d:SUBJ\" " +
934 " xlink:type=\"simple\" " +
935 " xlink:href=\"#token-GOE/AGA/01784-p199\">ich</span>" +
936 " <span xml:id=\"token-GOE/AGA/01784-p202\">" +
937 " <span xlink:title=\"malt/d:OBJA\" " +
938 " xlink:type=\"simple\" " +
939 " xlink:href=\"#token-GOE/AGA/01784-p199\">mich</span>" +
940 " </span>" +
941 "</span>" +
942 "<span class=\"context-right\"></span>";
943
944
945 it('should be initializable', function () {
Akrond8692de2018-07-26 13:06:01 +0200946 var tree = matchRelClass.create();
Akron671fdb92017-09-12 18:09:46 +0200947 expect(tree.size()).toBe(0);
948 });
949
950 it('should be parse string data', function () {
Akrond8692de2018-07-26 13:06:01 +0200951 var tree = matchRelClass.create(relExample);
Akron671fdb92017-09-12 18:09:46 +0200952 expect(tree.size()).toBe(4);
953 });
Akron0a785d42020-10-12 17:21:46 +0200954
955 it('should accept missing data', function () {
956 var relExample2 = "<span class=\"context-left\"><\/span>"+
957 "<span class=\"match\">"+
958 "{{"+
959 "<span xml:id=\"token-WUD17\/D95\/09441-p180\">"+
960 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p179\">Wikiläum<\/span>"+
961 "<\/span>"+
962 "|"+
963 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p180\">Silber<\/span>"+
964 "|"+
965 "<span xlink:title=\"malt\/d:DET\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p183\">Dein<\/span>"+
966 " "+
967 "<span xml:id=\"token-WUD17\/D95\/09441-p183\">"+
968 "<span xlink:title=\"malt\/d:ROOT\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p179-196\">Freund<\/span>"+
969 "<\/span>"+
970 " "+
971 "<span xlink:title=\"malt\/d:DET\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p185\">der<\/span>"+
972 " "+
973 "<span xml:id=\"token-WUD17\/D95\/09441-p185-186\">"+
974 "<span xml:id=\"token-WUD17\/D95\/09441-p185\">"+
975 "<mark>"+
976 "<span xlink:title=\"malt\/d:GMOD\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p183\">Baum<\/span>"+
977 "<\/mark>"+
978 "<\/span>"+
979 "| "+
980 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p185-186\">09:38<\/span>"+
981 "<\/span>"+
982 ", "+
983 "<span xlink:title=\"malt\/d:ATTR\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p188\">22.<\/span>"+
984 " "+
985 "<span xml:id=\"token-WUD17\/D95\/09441-p188\">"+
986 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p183\">Aug.<\/span>"+
987 "<\/span>"+
988 " "+
989 "<span xml:id=\"token-WUD17\/D95\/09441-p189\">"+
990 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p188\">2015<\/span>"+
991 "<\/span>"+
992 " ("+
993 "<span xlink:title=\"malt\/d:PAR\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p189\">CEST<\/span>"+
994 ")"+
995 "<\/span>"+
996 "<span class=\"context-right\"><\/span>";
997 var tree = matchRelClass.create(relExample2);
998 expect(tree.size()).toBe(18);
999 var treeElement = tree.element();
1000 expect(treeElement.tagName).toEqual("svg");
1001 tree.show();
1002 expect(treeElement.querySelector("text[text-anchor=\"middle\"]").textContent).toEqual("APP");
1003 });
Akron671fdb92017-09-12 18:09:46 +02001004 });
1005
1006
Nils Diewald7c8ced22015-04-15 19:21:00 +00001007 describe('KorAP.MatchTreeMenu', function () {
Akrond8692de2018-07-26 13:06:01 +02001008 beforeAll(beforeAllFunc);
1009 afterAll(afterAllFunc);
Nils Diewald7c8ced22015-04-15 19:21:00 +00001010
1011 it('should be initializable', function () {
Akrond8692de2018-07-26 13:06:01 +02001012 var menu = matchTreeMenuClass.create([
Akron671fdb92017-09-12 18:09:46 +02001013 ['cnx/c', 'cnx', 'c'],
1014 ['xip/c', 'xip', 'c']
Akrond8692de2018-07-26 13:06:01 +02001015 ], matchTreeItemClass);
Nils Diewald7c8ced22015-04-15 19:21:00 +00001016
Akrond8692de2018-07-26 13:06:01 +02001017 expect(menu.itemClass()).toEqual(matchTreeItemClass);
Nils Diewald7c8ced22015-04-15 19:21:00 +00001018 expect(menu.element().nodeName).toEqual('UL');
Akronaba7a5a2016-08-15 21:58:33 +02001019 expect(menu.element().classList.contains('visible')).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001020 expect(menu.limit()).toEqual(6);
1021 menu.show();
Akronaba7a5a2016-08-15 21:58:33 +02001022 expect(menu.element().classList.contains('visible')).toBeTruthy();
Akronc1457bf2015-06-11 19:24:00 +02001023 expect(menu.item(0).active()).toBe(false);
Nils Diewald7c8ced22015-04-15 19:21:00 +00001024 });
Nils Diewalda297f062015-04-02 00:23:46 +00001025 });
hebasta999d6c12018-04-23 12:44:59 +02001026
1027 //Test display and sorting of meta information
1028 describe('KorAP.Meta', function(){
Akrond8692de2018-07-26 13:06:01 +02001029 beforeAll(beforeAllFunc);
1030 afterAll(afterAllFunc);
1031
1032 var met = metaClass.create(match, fields);
hebasta999d6c12018-04-23 12:44:59 +02001033 var mel = met.element();
1034
1035 // Meta information should be parsed into a list
1036 it('should parse in a meta view', function(){
Akronfa32c9d2018-11-20 15:39:18 +01001037 expect(mel.tagName).toEqual('DL');
1038 expect(mel.children[0].tagName).toEqual('DIV');
1039 expect(mel.children[0].children[0].tagName).toEqual('DT');
1040 expect(mel.children[0].children[0].attributes[0].name).toEqual('title');
1041 expect(mel.children[0].children[1].tagName).toEqual('DD');
1042 expect(mel.children[0].children[1].getAttribute('data-type')).toEqual('type:text')
hebasta999d6c12018-04-23 12:44:59 +02001043
Akronfa32c9d2018-11-20 15:39:18 +01001044 expect(mel.children[0].children[0].firstChild.nodeValue).toEqual('author');
1045 expect(mel.children[0].children[1].firstChild.nodeValue).toEqual('Sprachpfleger, u.a.');
1046 expect(mel.children[0].children[0].attributes[0].value).toEqual('author');
hebasta999d6c12018-04-23 12:44:59 +02001047 });
1048
1049
Akronfa32c9d2018-11-20 15:39:18 +01001050 /* The keywords in the meta information list should be formatted to be able
1051 to chose each keyword separately in the corpusByMatch assistant. */
1052 it('keywords should be formatted', function(){
hebasta999d6c12018-04-23 12:44:59 +02001053
Akronfa32c9d2018-11-20 15:39:18 +01001054 //type:string or type:keyword should b not relevant
1055 expect(mel.children[1].children[1].getAttribute('data-type')).toEqual('type:string')
1056 expect(mel.children[1].children[1].classList.contains('metakeyvalues')).toBeTruthy;
1057 expect(mel.children[1].children[1].children[0].tagName).toEqual('DIV');
1058 expect(mel.children[1].children[1].children[0].firstChild.nodeValue).toEqual('corenlp');
1059 expect(mel.children[1].children[1].children[1].tagName).toEqual('DIV');
1060 expect(mel.children[1].children[1].children[1].firstChild.nodeValue).toEqual('corenlp\/constituency');
1061
1062 expect(mel.children[2].children[1].classList.contains('metakeyvalues')).toBeTruthy;
1063 expect(mel.children[2].children[1].children[0].tagName).toEqual('DIV');
1064 expect(mel.children[2].children[1].children[0].firstChild.nodeValue).toEqual('kultur');
1065 expect(mel.children[2].children[1].children[1].tagName).toEqual('DIV');
1066 expect(mel.children[2].children[1].children[1].firstChild.nodeValue).toEqual('film');
hebasta999d6c12018-04-23 12:44:59 +02001067 });
Akrona0ea3c32018-12-14 18:33:48 +01001068
1069 it('attachements should be formatted', function(){
Akron0f700762022-01-11 17:21:16 +01001070 //type:attachement with a link (legacy)
Akrona0ea3c32018-12-14 18:33:48 +01001071 expect(mel.children[3].children[1].getAttribute('data-type')).toEqual('type:attachement')
Akron0f700762022-01-11 17:21:16 +01001072 expect(mel.children[3].children[1].classList.contains('metakeyvalues')).toBeFalsy;
1073 expect(mel.children[3].children[0].firstChild.nodeValue).toEqual('xlink');
1074 expect(mel.children[3].children[1].firstChild.textContent).toEqual('Cool');
1075 expect(mel.children[3].children[1].firstChild.tagName).toEqual('A');
Akrona0ea3c32018-12-14 18:33:48 +01001076 expect(mel.children[3].children[1].firstChild.getAttribute('href')).toEqual('https://de.wikipedia.org/wiki/Beispiel');
Akrond3bb85b2019-02-08 10:15:13 +01001077
Akron0f700762022-01-11 17:21:16 +01001078 //type:attachement with a link (uri encoded)
Akrond3bb85b2019-02-08 10:15:13 +01001079 expect(mel.children[4].children[1].getAttribute('data-type')).toEqual('type:attachement')
Akron0f700762022-01-11 17:21:16 +01001080 expect(mel.children[4].children[1].classList.contains('metakeyvalues')).toBeFalsy;
1081 expect(mel.children[4].children[0].firstChild.nodeValue).toEqual('xlink2');
1082 expect(mel.children[4].children[1].firstChild.textContent).toEqual('Hallo!');
1083 expect(mel.children[4].children[1].firstChild.tagName).toEqual('A');
1084 expect(mel.children[4].children[1].firstChild.getAttribute('href')).toEqual('https://www.test.de');
Akrond7d3ceb2022-02-07 20:13:09 +01001085
Akron0f700762022-01-11 17:21:16 +01001086 //type:attachement with plain text
1087 expect(mel.children[5].children[1].getAttribute('data-type')).toEqual('type:attachement')
1088 expect(mel.children[5].children[1].classList.contains('metakeyvalues')).toBeFalsy;
Akrond7d3ceb2022-02-07 20:13:09 +01001089 expect(mel.children[5].children[0].firstChild.nodeValue).toEqual('xlink3');
1090 expect(mel.children[5].children[1].firstChild.nodeValue).toEqual('[INVALID URI]');
1091
1092 //type:attachement with plain text
1093 expect(mel.children[6].children[1].getAttribute('data-type')).toEqual('type:attachement')
1094 expect(mel.children[6].children[1].classList.contains('metakeyvalues')).toBeFalsy;
1095 expect(mel.children[6].children[0].firstChild.nodeValue).toEqual('z-reference');
1096 expect(mel.children[6].children[1].firstChild.nodeValue).toEqual('This is a reference');
Akrond3bb85b2019-02-08 10:15:13 +01001097 });
Akrona0ea3c32018-12-14 18:33:48 +01001098
1099
hebasta999d6c12018-04-23 12:44:59 +02001100
Akronfa32c9d2018-11-20 15:39:18 +01001101 // Meta information should be sorted alphabetically
1102 it('should be alphabetically sorted', function(){
1103 var a = mel.children[0].children[0].firstChild.nodeValue;
1104 var b = mel.children[1].children[0].firstChild.nodeValue;
1105 var c = mel.children[2].children[0].firstChild.nodeValue;
1106 expect(a.localeCompare(b)).toBe(-1);
1107 expect(b.localeCompare(c)).toBe(-1);
Akrona0ea3c32018-12-14 18:33:48 +01001108 });
1109
1110
1111 it('should handle attachements', function () {
1112 let uri = attachementClass.create("data:text/plain;title=new,Hallo");
1113 expect(uri.contentType).toEqual("text/plain");
1114
1115 expect(uri.payload).toEqual("Hallo");
1116 expect(uri.base64).toBeFalsy();
1117 expect(uri.isLink).toBeFalsy();
1118 expect(uri.param["title"]).toEqual("new");
1119
1120 uri = attachementClass.create("data:application/x.korap-link,https://de.wikipedia.org/wiki/Beispiel");
1121 expect(uri.contentType).toEqual("application/x.korap-link");
1122 expect(uri.payload).toEqual("https://de.wikipedia.org/wiki/Beispiel");
1123 expect(uri.base64).toBeFalsy();
1124 expect(uri.isLink).toBeTruthy();
1125 expect(uri.inline().textContent).toEqual("https://de.wikipedia.org/wiki/Beispiel");
1126 expect(uri.inline().nodeType).toEqual(1);
1127 expect(uri.inline().tagName).toEqual("A");
1128 expect(uri.inline().getAttribute("rel")).toEqual("noopener noreferrer");
1129
1130
1131 uri = attachementClass.create("data:application/x.korap-link;title=Das ist ein Titel,https://de.wikipedia.org/wiki/Beispiel");
1132 expect(uri.contentType).toEqual("application/x.korap-link");
1133 expect(uri.payload).toEqual("https://de.wikipedia.org/wiki/Beispiel");
1134 expect(uri.base64).toBeFalsy();
1135 expect(uri.isLink).toBeTruthy();
1136 expect(uri.inline().textContent).toEqual("Das ist ein Titel");
1137 expect(uri.inline().nodeType).toEqual(1);
1138 expect(uri.inline().tagName).toEqual("A");
1139 expect(uri.inline().getAttribute("rel")).toEqual("noopener noreferrer");
1140
1141
1142 uri = attachementClass.create("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D");
1143 expect(uri.contentType).toEqual("text/plain");
1144 expect(uri.payload).toEqual("Hello, World!");
1145 expect(uri.base64).toBeTruthy();
1146 expect(uri.isLink).toBeFalsy();
1147 expect(uri.inline().nodeType).toEqual(3);
1148 expect(uri.inline().textContent).toEqual("Hello, World!");
1149
1150 uri = attachementClass.create("data:text/plain;title= new ; subTitle = old ;base64,SGVsbG8sIFdvcmxkIQ%3D%3D");
1151 expect(uri.contentType).toEqual("text/plain");
1152 expect(uri.payload).toEqual("Hello, World!");
1153 expect(uri.param["title"]).toEqual("new");
1154 expect(uri.param["subTitle"]).toEqual("old");
1155 expect(uri.base64).toBeTruthy();
1156 expect(uri.isLink).toBeFalsy();
1157 expect(uri.inline().nodeType).toEqual(3);
1158 expect(uri.inline().textContent).toEqual("Hello, World!");
1159 });
hebasta999d6c12018-04-23 12:44:59 +02001160 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001161 // table = view.toTable();
1162 // table.sortBy('');
1163 // table.element();
1164 // tree = view.toTree();
1165 // tree.element();
Nils Diewalda297f062015-04-02 00:23:46 +00001166});