blob: 43b9ac6a1f9b6b0b6f210d91fadbc8ce61b2d1c0 [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 },
Akrone3b566d2026-03-05 17:40:10 +0100109 {
110 "@type": "koral:field",
111 "key": "zz-notinindex",
112 "type": "type:text",
113 "comment": "notinindex",
114 "value": "Stored but not indexed"
115 },
Akrond8692de2018-07-26 13:06:01 +0200116 ];
117
118
Akron5dc31172019-05-15 18:43:48 +0200119 var snippet = "<span class=\"context-left\"><\/span>"+
120 "<span class=\"match\">" +
Akron1a780fe2019-05-21 15:59:00 +0200121 "<span class=\"cutted\"><\/span>" +
122 "Außerdem " +
Akron5dc31172019-05-15 18:43:48 +0200123 "<span title=\"cnx/l:meist\">" +
Akrond8692de2018-07-26 13:06:01 +0200124 " <span title=\"cnx/p:ADV\">" +
125 " <span title=\"cnx/syn:@PREMOD\">" +
126 " <span title=\"mate/l:meist\">" +
127 " <span title=\"mate/l:meist\">" +
128 " <span title=\"mate/p:ADV\">" +
129 " <span title=\"opennlp/p:ADV\">meist</span>" +
130 " </span>" +
131 " </span>" +
132 " </span>" +
133 " </span>" +
134 " </span>" +
135 "</span>" +
Akronad1e46a2018-09-19 15:55:40 +0200136 "<mark>" +
Akrond8692de2018-07-26 13:06:01 +0200137 "<span title=\"cnx/l:deutlich\">" +
138 " <span title=\"cnx/p:A\">" +
139 " <span title=\"cnx/syn:@PREMOD\">" +
140 " <span title=\"mate/l:deutlich\">" +
141 " <span title=\"mate/m:degree:pos\">" +
142 " <span title=\"mate/p:ADJD\">" +
143 " <span title=\"opennlp/p:ADJD\">deutlich</span>" +
144 " </span>" +
145 " </span>" +
146 " </span>" +
147 " </span>" +
148 " </span>" +
149 "</span>" +
Akronad1e46a2018-09-19 15:55:40 +0200150 "</mark>" +
Akron158fce12019-12-17 14:43:29 +0100151 "<span title=\"dgd/para:incident\">▮</span>" +
Akrond8692de2018-07-26 13:06:01 +0200152 "<span title=\"cnx/l:fähig\">" +
153 " <span title=\"cnx/l:leistung\">" +
154 " <span title=\"cnx/p:A\">" +
155 " <span title=\"cnx/p:ADJA\">" +
156 " <span title=\"cnx/syn:@NH\">" +
157 " <span title=\"mate/l:leistungsfähig\">" +
158 " <span title=\"mate/m:degree:comp\">" +
159 " <span title=\"mate/p:ADJD\">" +
160 " <span title=\"opennlp/p:ADJD\">leistungsfähiger</span>" +
161 " </span>" +
162 " </span>" +
163 " </span>" +
164 " </span>" +
165 " </span>" +
166 " </span>" +
167 " </span>" +
Akron5dc31172019-05-15 18:43:48 +0200168 "</span>" +
169 " und robust sind auch die anderen Traktoren, die hier der Übersicht wegen keine Erwähnung finden können." +
170 "<span class=\"cutted\"><\/span>" +
Akrond8692de2018-07-26 13:06:01 +0200171 "</span>";
172
173 var treeSnippet =
174 "<span class=\"context-left\"></span>" +
175 "<span class=\"match\">" +
176 " <span title=\"xip/c:MC\">" +
177 " <span title=\"xip/c:TOP\">" +
178 " <span title=\"xip/c:PP\">" +
179 " <span title=\"xip/c:PREP\">Mit</span>" +
180 " <span title=\"xip/c:NP\">" +
181 " <span title=\"xip/c:DET\">dieser</span>" +
182 " <span title=\"xip/c:NPA\">" +
183 " <span title=\"xip/c:NOUN\">Methode</span>" +
184 " </span>" +
185 " </span>" +
186 " </span>" +
187 " <span title=\"xip/c:VERB\">ist</span>" +
188 " <mark>" +
189 " <span title=\"xip/c:NP\">" +
190 " <span title=\"xip/c:PRON\">es</span>" +
191 " </span>" +
192 " <span title=\"xip/c:AP\">" +
193 " <span title=\"xip/c:ADV\">nun</span>" +
194 " <span title=\"xip/c:ADJ\">möglich</span>" +
195 " </span>" +
196 " </mark>" +
197 " <span title=\"xip/c:ADV\">z. B.</span>" +
198 " <span title=\"xip/c:NPA\">" +
199 " <span title=\"xip/c:NP\">" +
200 " <span title=\"xip/c:NOUN\">Voice</span>" +
201 " </span>" +
202 " </span>" + "(" +
203 " <span title=\"xip/c:INS\">" +
204 " <span title=\"xip/c:NPA\">" +
205 " <span title=\"xip/c:NP\">" +
206 " <span title=\"xip/c:NOUN\">Sprache</span>" +
207 " </span>" +
208 " </span>" +
209 " </span>" + ")" +
210 " <span title=\"xip/c:VERB\">bevorzugt</span>" +
211 " <span title=\"xip/c:PP\">" +
212 " <span title=\"xip/c:PREP\">in</span>" +
213 " <span title=\"xip/c:NP\">" +
214 " <span title=\"xip/c:PRON\">der</span>" +
215 " </span>" +
216 " <span title=\"xip/c:NPA\">" +
217 " <span title=\"xip/c:NP\">" +
218 " <span title=\"xip/c:NOUN\">Bridge</span>" +
219 " </span>" +
220 " </span>" +
221 " </span>" +
222 " <span title=\"xip/c:INFC\">" +
223 " <span title=\"xip/c:INS\">" +
224 " <span title=\"xip/c:VERB\">weiterzugeben</span>" +
225 " </span>" +
226 " </span>" +
227 " </span>" +
228 " </span>" +
229 "</span>" +
230 "<span class=\"context-right\"></span>";
231
Akronb7749052022-07-22 18:03:26 +0200232 var snippetDiffToken = "<span class=\"context-left\"><\/span>"+
233 "<span class=\"match\">" +
234 "<span class=\"cutted\"><\/span>" +
235 "Außerdem " +
236 "<span title=\"cnx/l:meist\">" +
237 " <span title=\"cnx/p:ADV\">" +
238 " <span title=\"cnx/syn:@PREMOD\">" +
239 " <span title=\"mate/l:meist\">" +
240 " <span title=\"mate/p:ADV\">" +
241 " <span title=\"opennlp/p:ADV\">Диес</span>" +
242 " </span>" +
243 " </span>" +
244 " </span>" +
245 " </span>" +
246 "</span>" +
247 "<mark>" +
248 "<span title=\"cnx/l:deutlich\">" +
249 " <span title=\"cnx/p:A\">" +
250 " <span title=\"cnx/syn:@PREMOD\">" +
251 " <span title=\"mate/l:deutlich\">" +
252 " <span title=\"mate/m:degree:pos\">" +
253 " <span title=\"mate/p:ADJD\">" +
254 " <span title=\"opennlp/p:ADJD\">ист</span>" +
255 " </span>" +
256 " </span>" +
257 " </span>" +
258 " </span>" +
259 " </span>" +
260 "</span>" +
261 "<span title=\"cnx/l:deutlich\">" +
262 " <span title=\"cnx/p:A\">" +
263 " <span title=\"cnx/syn:@PREMOD\">" +
264 " <span title=\"mate/l:deutlich\">" +
265 " <span title=\"mate/m:degree:pos\">" +
266 " <span title=\"mate/p:ADJD\">" +
267 " <span title=\"opennlp/p:ADJD\">Беиспиел</span>" +
268 " </span>" +
269 " </span>" +
270 " </span>" +
271 " </span>" +
272 " </span>" +
273 "</span>" +
274 "</mark>" +
275 ")" +
276 "<span class=\"cutted\"><\/span>" +
277 "</span>";
278
279
Akron3bdac532019-03-04 13:24:43 +0100280 var treeSnippetHierarchy =
281 "<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 +0200282
Akron158fce12019-12-17 14:43:29 +0100283 function matchElementFactory () {
Akrond8692de2018-07-26 13:06:01 +0200284 var me = document.createElement('li');
285
286 me.setAttribute(
287 'data-available-info',
288 'base/s=spans corenlp/c=spans corenlp/ne=tokens corenlp/p=tokens' +
289 ' corenlp/s=spans glemm/l=tokens mate/l=tokens mate/m=tokens' +
290 ' mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens' +
291 ' tt/p=tokens tt/s=spans');
292
293 me.setAttribute('data-corpus-id', 'WPD');
294 me.setAttribute('data-doc-id', 'FFF');
295 me.setAttribute('data-text-id', '01460');
296 me.setAttribute('data-text-sigle', 'WPD/FFF/01460');
297 me.setAttribute('data-match-id', 'p119-120');
298 me.innerHTML = '<div><div class="snippet">check</div></div><p class="ref">me</p>';
299 return me;
300 };
301
302 function matchElementReal () {
303 var me = document.createElement('em');
304 me.innerHTML =
305 '<li data-match-id="p85183-85184"' +
306 ' data-text-sigle="GOE/AGI/00000"' +
307 ' 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"' +
308 ' 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;}"' +
309 ' id="GOE/AGI/00000#p85183-85184">' +
310 '<div>' +
311 '<div class="flag"></div>' +
312 '<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>' +
313 '</div>' +
314 '<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>' +
315 '</li>';
316 return me.firstChild;
317 };
318
319 var beforeAllFunc = function () {
320 // Override getMatchInfo API call
321 KorAP.API.getMatchInfo = function (x, param, cb) {
322 if (param['spans'] === undefined || param['spans'] === false)
323 cb({ "snippet": snippet });
324 else
325 cb({ "snippet": treeSnippet });
326 };
327 };
328
329 var afterAllFunc = function () {
330 KorAP.API.getMatchInfo = undefined;
hebasta87f1b1f2019-07-30 13:03:23 +0200331 KorAP.TreeMenu = undefined;
Akrond8692de2018-07-26 13:06:01 +0200332 var body = document.body;
hebasta87f1b1f2019-07-30 13:03:23 +0200333 var i = body.children.length - 1;
334 while (i >= 0) {
Akrond8692de2018-07-26 13:06:01 +0200335 if (body.children[i].nodeType && body.children[i].nodeType === 1) {
336 if (!body.children[i].classList.contains("jasmine_html-reporter")) {
337 body.removeChild(body.children[i]);
338 };
339 };
hebasta87f1b1f2019-07-30 13:03:23 +0200340 i--;
Akrond8692de2018-07-26 13:06:01 +0200341 };
342 };
Akron671fdb92017-09-12 18:09:46 +0200343
Nils Diewald7c8ced22015-04-15 19:21:00 +0000344 describe('KorAP.InfoLayer', function () {
Akrond8692de2018-07-26 13:06:01 +0200345 beforeAll(beforeAllFunc);
346 afterAll(afterAllFunc);
Nils Diewalda297f062015-04-02 00:23:46 +0000347
Nils Diewald7c8ced22015-04-15 19:21:00 +0000348 it('should be initializable', function () {
349 expect(
Akron671fdb92017-09-12 18:09:46 +0200350 function() { infoClass.create() }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000351 ).toThrow(new Error("Missing parameters"));
Nils Diewalda297f062015-04-02 00:23:46 +0000352
Nils Diewald7c8ced22015-04-15 19:21:00 +0000353 expect(
Akron671fdb92017-09-12 18:09:46 +0200354 function() { infoClass.create("base") }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000355 ).toThrow(new Error("Missing parameters"));
Nils Diewalda297f062015-04-02 00:23:46 +0000356
Nils Diewald7c8ced22015-04-15 19:21:00 +0000357 var layer = infoClass.create("base", "s");
358 expect(layer).toBeTruthy();
359 expect(layer.foundry).toEqual("base");
360 expect(layer.layer).toEqual("s");
361 expect(layer.type).toEqual("tokens");
Nils Diewalda297f062015-04-02 00:23:46 +0000362
Nils Diewald7c8ced22015-04-15 19:21:00 +0000363 layer = infoClass.create("cnx", "syn", "spans");
364 expect(layer).toBeTruthy();
365 expect(layer.foundry).toEqual("cnx");
366 expect(layer.layer).toEqual("syn");
367 expect(layer.type).toEqual("spans");
Nils Diewald58141332015-04-07 16:18:45 +0000368 });
369 });
Nils Diewalda297f062015-04-02 00:23:46 +0000370
Nils Diewalda297f062015-04-02 00:23:46 +0000371
Nils Diewald7c8ced22015-04-15 19:21:00 +0000372 describe('KorAP.Match', function () {
Akrond8692de2018-07-26 13:06:01 +0200373 beforeAll(beforeAllFunc);
374 afterAll(afterAllFunc);
375
Nils Diewald7c8ced22015-04-15 19:21:00 +0000376 var match = {
377 'corpusID' : 'WPD',
378 'docID' : 'UUU',
379 'textID' : '01912',
380 'matchID' : 'p121-122',
Akron0a6768f2016-07-13 18:00:43 +0200381 'textSigle' : 'WPD/UUU/01912',
Nils Diewald7c8ced22015-04-15 19:21:00 +0000382 'available' : available
383 };
384
Nils Diewald7c8ced22015-04-15 19:21:00 +0000385 it('should be initializable by Object', function () {
386 expect(function() {
Akron671fdb92017-09-12 18:09:46 +0200387 matchClass.create()
Nils Diewald7c8ced22015-04-15 19:21:00 +0000388 }).toThrow(new Error('Missing parameters'));
389
390 expect(matchClass.create(match)).toBeTruthy();
391
392 var m = matchClass.create(match);
Akron0a6768f2016-07-13 18:00:43 +0200393 expect(m.textSigle).toEqual("WPD/UUU/01912");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000394 expect(m.matchID).toEqual("p121-122");
395
Akron06d4d1f2024-06-05 11:59:20 +0200396 // /corpus/WPD/UUU.01912/p121-122?spans=false&foundry=*
Nils Diewald7c8ced22015-04-15 19:21:00 +0000397 var m = matchClass.create(match);
398
399 // Spans:
400 var spans = m.getSpans();
401 expect(spans[0].foundry).toEqual("base");
402 expect(spans[0].layer).toEqual("s");
403
404 expect(spans[1].foundry).toEqual("corenlp");
405 expect(spans[1].layer).toEqual("c");
406
407 expect(spans[2].foundry).toEqual("corenlp");
408 expect(spans[2].layer).toEqual("s");
409
410 expect(spans[spans.length-1].foundry).toEqual("tt");
411 expect(spans[spans.length-1].layer).toEqual("s");
412
413 // Tokens:
414 var tokens = m.getTokens();
415 expect(tokens[0].foundry).toEqual("corenlp");
416 expect(tokens[0].layer).toEqual("ne");
417
418 expect(tokens[1].foundry).toEqual("corenlp");
419 expect(tokens[1].layer).toEqual("p");
420
421 expect(tokens[tokens.length-1].foundry).toEqual("tt");
422 expect(tokens[tokens.length-1].layer).toEqual("p");
Nils Diewald58141332015-04-07 16:18:45 +0000423 });
Nils Diewalda297f062015-04-02 00:23:46 +0000424
425
Akroncdb0baa2016-11-07 01:52:11 +0100426 it('should be initializable by Node 1', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000427 var m = matchClass.create(matchElementFactory());
Akron0a6768f2016-07-13 18:00:43 +0200428 expect(m.textSigle).toEqual("WPD/FFF/01460");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000429 expect(m.matchID).toEqual("p119-120");
Nils Diewalda297f062015-04-02 00:23:46 +0000430
Nils Diewald7c8ced22015-04-15 19:21:00 +0000431 // Spans:
432 var spans = m.getSpans();
433 expect(spans[0].foundry).toEqual("base");
434 expect(spans[0].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000435
Nils Diewald7c8ced22015-04-15 19:21:00 +0000436 expect(spans[1].foundry).toEqual("corenlp");
437 expect(spans[1].layer).toEqual("c");
Nils Diewalda297f062015-04-02 00:23:46 +0000438
Nils Diewald7c8ced22015-04-15 19:21:00 +0000439 expect(spans[2].foundry).toEqual("corenlp");
440 expect(spans[2].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000441
Nils Diewald7c8ced22015-04-15 19:21:00 +0000442 expect(spans[spans.length-1].foundry).toEqual("tt");
443 expect(spans[spans.length-1].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000444
Nils Diewald7c8ced22015-04-15 19:21:00 +0000445 // Tokens:
446 var tokens = m.getTokens();
447 expect(tokens[0].foundry).toEqual("corenlp");
448 expect(tokens[0].layer).toEqual("ne");
Nils Diewalda297f062015-04-02 00:23:46 +0000449
Nils Diewald7c8ced22015-04-15 19:21:00 +0000450 expect(tokens[1].foundry).toEqual("corenlp");
451 expect(tokens[1].layer).toEqual("p");
Nils Diewalda297f062015-04-02 00:23:46 +0000452
Nils Diewald7c8ced22015-04-15 19:21:00 +0000453 expect(tokens[tokens.length-1].foundry).toEqual("tt");
454 expect(tokens[tokens.length-1].layer).toEqual("p");
Nils Diewalda297f062015-04-02 00:23:46 +0000455
Nils Diewald7c8ced22015-04-15 19:21:00 +0000456 });
Nils Diewalda297f062015-04-02 00:23:46 +0000457
Akroncdb0baa2016-11-07 01:52:11 +0100458 it('should be initializable by Node 2', function () {
459 var ele = matchElementReal();
460 var m = matchClass.create(ele);
461 expect(m.textSigle).toEqual("GOE/AGI/00000");
462 expect(m.matchID).toEqual("p85183-85184");
463 });
464
Akron3c390c42020-03-30 09:06:21 +0200465 it('should be initializable when active', function () {
466 var e = matchElementFactory();
467 e.setAttribute('class', 'active');
468
469 expect(e.classList.contains('active')).toBe(true);
470 expect(e["_match"]).toBe(undefined);
471
472 var m = matchClass.create(e);
473
474 expect(e["_match"]).not.toBe(undefined);
475
476 // Open the match
477 m.init();
478
479 expect(e["_match"]).not.toBe(undefined);
480
481 actions = e.querySelector("p.ref > div.action.button-group").children;
482
483 expect(actions[0].getAttribute("class")).toEqual("metatable");
484 expect(actions[1].getAttribute("class")).toEqual("info");
485 expect(actions[2].getAttribute("class")).toEqual("tree");
486
487 // Close the match
488 expect(e.querySelector("div.action.button-group > span.minimize")).toBe(null);
489 });
Akroncdb0baa2016-11-07 01:52:11 +0100490
Nils Diewald7c8ced22015-04-15 19:21:00 +0000491 it('should react to gui actions', function () {
492 var e = matchElementFactory();
Nils Diewalda297f062015-04-02 00:23:46 +0000493
Nils Diewald7c8ced22015-04-15 19:21:00 +0000494 expect(e.classList.contains('active')).toBe(false);
495 expect(e["_match"]).toBe(undefined);
Nils Diewalda297f062015-04-02 00:23:46 +0000496
Nils Diewald7c8ced22015-04-15 19:21:00 +0000497 var m = matchClass.create(e);
498
499 expect(e.classList.contains('active')).toBe(false);
500 expect(e["_match"]).not.toBe(undefined);
hebasta87f1b1f2019-07-30 13:03:23 +0200501
Nils Diewald7c8ced22015-04-15 19:21:00 +0000502 // Open the match
503 m.open();
hebasta87f1b1f2019-07-30 13:03:23 +0200504
Nils Diewald7c8ced22015-04-15 19:21:00 +0000505 expect(e.classList.contains('active')).toBe(true);
506 expect(e["_match"]).not.toBe(undefined);
507
Akronbfe912c2018-07-17 19:30:52 +0200508 actions = e.querySelector("p.ref > div.action.button-group").children;
Akrond141a362018-07-10 18:12:13 +0200509
Akronbfe912c2018-07-17 19:30:52 +0200510 expect(actions[0].getAttribute("class")).toEqual("metatable");
Akronc296ca22018-04-24 16:35:26 +0200511 expect(actions[1].getAttribute("class")).toEqual("info");
512 expect(actions[2].getAttribute("class")).toEqual("tree");
Akron3c390c42020-03-30 09:06:21 +0200513
514 expect(e.querySelector("div.action.button-group > span.minimize")).not.toBe(null);
Akronc296ca22018-04-24 16:35:26 +0200515
Nils Diewald7c8ced22015-04-15 19:21:00 +0000516 // Close the match
Akronec6bb8e2018-08-29 13:07:56 +0200517 m.minimize();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000518 expect(e.classList.contains('active')).toBe(false);
519 expect(e["_match"]).not.toBe(undefined);
Nils Diewald58141332015-04-07 16:18:45 +0000520 });
Akrone57e8802020-10-17 08:23:45 +0200521
522 it('should toggle', function () {
523 var e = matchElementFactory();
524
525 expect(e.classList.contains('active')).toBe(false);
526 expect(e["_match"]).toBe(undefined);
527
528 var m = matchClass.create(e);
529
530 expect(e.classList.contains('active')).toBe(false);
531 expect(e["_match"]).not.toBe(undefined);
532
533 // Open the match
534 m.open();
535
536 expect(e.classList.contains('active')).toBe(true);
537 expect(e["_match"]).not.toBe(undefined);
538
539 m.toggle();
540
541 expect(e.classList.contains('active')).toBe(false);
542 expect(e["_match"]).not.toBe(undefined);
543
544 m.toggle();
545
546 expect(e.classList.contains('active')).toBe(true);
547 expect(e["_match"]).not.toBe(undefined);
548 });
549
Akrond8692de2018-07-26 13:06:01 +0200550 it('should open tree menu', function () {
Akronc296ca22018-04-24 16:35:26 +0200551 var e = matchElementFactory();
552 var m = matchClass.create(e);
553 m.open();
Akronbfe912c2018-07-17 19:30:52 +0200554 var relation = e.querySelector("p.ref > div.action.button-group > span:nth-of-type(3)");
Akronc296ca22018-04-24 16:35:26 +0200555 expect(relation.getAttribute("class")).toEqual("tree");
Akron52ed22d2018-07-11 17:05:19 +0200556 expect(document.getElementsByClassName("button-group-list").length).toEqual(0);
Akronc296ca22018-04-24 16:35:26 +0200557 expect(document.activeElement.tagName).toEqual("BODY");
hebasta87f1b1f2019-07-30 13:03:23 +0200558
Akronc296ca22018-04-24 16:35:26 +0200559 // Show menu
560 relation.click();
Akron52ed22d2018-07-11 17:05:19 +0200561 expect(document.getElementsByClassName("button-group-list").length).toEqual(1);
Akronc296ca22018-04-24 16:35:26 +0200562 expect(document.activeElement.tagName).toEqual("UL");
hebasta87f1b1f2019-07-30 13:03:23 +0200563
Akronc296ca22018-04-24 16:35:26 +0200564 // Choose first tree
Akron52ed22d2018-07-11 17:05:19 +0200565 document.getElementsByClassName("button-group-list")[0].getElementsByTagName("li")[1].click();
Akronc296ca22018-04-24 16:35:26 +0200566 expect(e.querySelector("div.matchinfo div.matchtree h6 span").innerText).toEqual("corenlp");
567
568 // This should blur the focus
569 expect(document.activeElement.tagName).toEqual("BODY");
hebasta87f1b1f2019-07-30 13:03:23 +0200570
Akronc296ca22018-04-24 16:35:26 +0200571 });
572
573 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000574
Akron7f9a6a32018-07-18 15:05:23 +0200575 describe('KorAP.TableView', function () {
Akrond8692de2018-07-26 13:06:01 +0200576 beforeAll(beforeAllFunc);
577 afterAll(afterAllFunc);
Akron5dc31172019-05-15 18:43:48 +0200578
579 let longString = " und robust sind auch die anderen Traktoren, die hier der Übersicht wegen keine Erwähnung finden können.";
580
Akron7f9a6a32018-07-18 15:05:23 +0200581 var table;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000582
Akron7f9a6a32018-07-18 15:05:23 +0200583 var matchObj = matchClass.create(match);
584 var tableObj = tableClass.create(matchObj);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000585
586 var table1, table2;
587
Nils Diewald7c8ced22015-04-15 19:21:00 +0000588 it('should fail to load a table async', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200589 expect(tableObj).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000590
Akron7f9a6a32018-07-18 15:05:23 +0200591 tableObj.getData([], function (tablen) {
Akron671fdb92017-09-12 18:09:46 +0200592 table1 = tablen;
593 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000594 });
595 });
596
Akron671fdb92017-09-12 18:09:46 +0200597
Akronaeeb8252018-09-19 18:51:00 +0200598 xit('should\'nt be parsable (async)', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000599 expect(table1).not.toBeTruthy();
600 });
601
Nils Diewald7c8ced22015-04-15 19:21:00 +0000602
Nils Diewald7c8ced22015-04-15 19:21:00 +0000603 it('should be retrieved async', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200604 expect(tableObj).toBeTruthy();
605 tableObj.getData(undefined, function (x) {
Akron671fdb92017-09-12 18:09:46 +0200606 table = x;
607 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000608 });
609 });
Nils Diewalda297f062015-04-02 00:23:46 +0000610
Akron7f9a6a32018-07-18 15:05:23 +0200611 it('should parse into a table (async)', function () {
612 expect(table).toBeTruthy();
Akron5b1a6af2018-02-05 15:41:16 +0100613
Akron158fce12019-12-17 14:43:29 +0100614 expect(table.length()).toBe(8);
Akron7f9a6a32018-07-18 15:05:23 +0200615
Akron1a780fe2019-05-21 15:59:00 +0200616 expect(table.getToken(0)).toBe("");
617 expect(table.getToken(1)).toBe("Außerdem ");
618 expect(table.getToken(2)).toBe("meist");
619 expect(table.getToken(3)).toBe("deutlich");
Akron158fce12019-12-17 14:43:29 +0100620 expect(table.getToken(5)).toBe("leistungsfähiger");
621 expect(table.getToken(6)).toBe(longString);
Akron7f9a6a32018-07-18 15:05:23 +0200622
Akron1a780fe2019-05-21 15:59:00 +0200623 expect(table.getValue(2, "cnx", "p")[0]).toBe("ADV");
624 expect(table.getValue(2, "cnx", "syn")[0]).toBe("@PREMOD");
625 expect(table.getValue(2, "mate", "l")[0]).toBe("meist");
626 expect(table.getValue(2, "mate", "l")[1]).toBeUndefined();
Akron7f9a6a32018-07-18 15:05:23 +0200627
Akron158fce12019-12-17 14:43:29 +0100628 expect(table.getValue(5, "cnx", "l")[0]).toBe("fähig");
629 expect(table.getValue(5, "cnx", "l")[1]).toBe("leistung");
Akron7f9a6a32018-07-18 15:05:23 +0200630 });
Akronb7749052022-07-22 18:03:26 +0200631
Akron7f9a6a32018-07-18 15:05:23 +0200632 it('should be rendered async', function () {
Akron5b1a6af2018-02-05 15:41:16 +0100633 var e = table.element().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000634 expect(e.nodeName).toBe('TABLE');
635 expect(e.children[0].nodeName).toBe('THEAD');
636 var tr = e.children[0].children[0];
637 expect(tr.nodeName).toBe('TR');
638 expect(tr.children[0].nodeName).toBe('TH');
Nils Diewald58141332015-04-07 16:18:45 +0000639
Nils Diewald7c8ced22015-04-15 19:21:00 +0000640 expect(tr.children[0].firstChild.nodeValue).toBe('Foundry');
641 expect(tr.children[1].firstChild.nodeValue).toBe('Layer');
Akron1a780fe2019-05-21 15:59:00 +0200642
643 expect(tr.children[2].classList.contains('cutted')).toBeTruthy();
644 expect(tr.children[3].firstChild.nodeValue).toBe('Außerdem ');
645
646
647 expect(tr.children[4].firstChild.nodeValue).toBe('meist');
Akronad1e46a2018-09-19 15:55:40 +0200648 expect(tr.children[4].classList.contains('mark')).toBeFalsy();
Akron1a780fe2019-05-21 15:59:00 +0200649 expect(tr.children[5].firstChild.nodeValue).toBe('deutlich');
650 expect(tr.children[5].classList.contains('mark')).toBeTruthy();
Akron158fce12019-12-17 14:43:29 +0100651 expect(tr.children[6].firstChild.nodeValue).toBe('▮');
652 expect(tr.children[7].firstChild.nodeValue).toBe('leistungsfähiger');
653 expect(tr.children[7].classList.contains('mark')).toBeFalsy();
654 expect(tr.children[7].hasAttribute("title")).toBeFalsy();
655 expect(tr.children[8].firstChild.nodeValue).toBe(longString);
656 expect(tr.children[8].getAttribute("title")).toBe(longString);
657 expect(tr.children[9].classList.contains('cutted')).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000658
659 // first row
660 tr = e.children[1].children[0];
661 expect(tr.nodeName).toBe('TR');
662 expect(tr.getAttribute('tabindex')).toEqual('0');
663 expect(tr.children[0].nodeName).toBe('TH');
664 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
665 expect(tr.children[1].firstChild.nodeValue).toEqual('l');
Akron1a780fe2019-05-21 15:59:00 +0200666 expect(tr.children[4].firstChild.nodeValue).toEqual('meist');
667 expect(tr.children[5].firstChild.nodeValue).toEqual('deutlich');
Akron158fce12019-12-17 14:43:29 +0100668 expect(tr.children[6].firstChild).toBeNull();
669 expect(tr.children[7].firstChild.firstChild.nodeValue).toEqual('fähig');
670 expect(tr.children[7].lastChild.firstChild.nodeValue).toEqual('leistung');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000671
672 // second row
673 tr = e.children[1].children[1];
674 expect(tr.nodeName).toBe('TR');
675 expect(tr.getAttribute('tabindex')).toEqual('0');
676 expect(tr.children[0].nodeName).toBe('TH');
677 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
678 expect(tr.children[1].firstChild.nodeValue).toEqual('p');
Akron1a780fe2019-05-21 15:59:00 +0200679 expect(tr.children[4].firstChild.nodeValue).toEqual('ADV');
680 expect(tr.children[5].firstChild.nodeValue).toEqual('A');
Akron158fce12019-12-17 14:43:29 +0100681 expect(tr.children[6].firstChild).toBeNull();
682 expect(tr.children[7].firstChild.firstChild.nodeValue).toEqual('A');
683 expect(tr.children[7].lastChild.firstChild.nodeValue).toEqual('ADJA');
Akronf2279c42017-12-21 13:48:46 +0100684
Akron158fce12019-12-17 14:43:29 +0100685 expect(tr.children[7].firstChild.getAttribute("title")).toEqual('Adjective');
Akron1a780fe2019-05-21 15:59:00 +0200686 expect(tr.children[4].getAttribute("title")).toEqual('Adverb');
Nils Diewald58141332015-04-07 16:18:45 +0000687 });
Akron7f9a6a32018-07-18 15:05:23 +0200688
689
690 it('should parse into a table view (sync)', function () {
691 var matchElement = matchElementFactory();
692 expect(matchElement.tagName).toEqual('LI');
693
694 // Match
695 expect(matchElement.children[0].tagName).toEqual('DIV');
696
697 // snippet
698 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
699 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
700 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
701
702 // reference
703 expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
704 expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
705
706 // not yet
707 expect(matchElement.children[0].children[1]).toBe(undefined);
708
709 /*
710 var info = matchClass.create(matchElement).info();
711 info.showTable();
712 */
713 var matchObj = matchClass.create(matchElement);
714 matchObj.open();
715
716 // Match
717 expect(matchElement.children[0].tagName).toEqual('DIV');
718
719 // snippet
720 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
721
722 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
723
724 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
725
726 // reference
727
728 expect(matchElement.children[2].classList.contains('ref')).toBeTruthy();
729 expect(matchElement.children[2].childNodes[1].nodeValue).toEqual('me');
730
731 // Add table
732 matchObj.panel.addTable();
733
Akron386f1222022-12-21 16:26:11 +0100734 expect(matchObj.panel.type).toEqual('match');
735
Akron7f9a6a32018-07-18 15:05:23 +0200736 // now
737 var infotable = matchElement.children[1];
738 expect(infotable.tagName).toEqual('DIV');
739
740 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
741
742 expect(infotable.firstChild.firstChild.firstChild.classList.contains('matchtable')).toBeTruthy();
743
744 // expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
745 });
746
Akron158fce12019-12-17 14:43:29 +0100747 it('should parse into a table view with non-verbal elements (sync)', function () {
748 var matchElement = matchElementFactory();
749 expect(matchElement.tagName).toEqual('LI');
750 });
751
Akronb7749052022-07-22 18:03:26 +0200752 it('should parse into a table with non-latin characters', function () {
753 var matchElement = matchElementFactory();
754 expect(matchElement.tagName).toEqual('LI');
755
756 // Match
757 expect(matchElement.children[0].tagName).toEqual('DIV');
758
759 // snippet
760 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
761 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
762 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
763
764 // reference
765 expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
766 expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
767
768 // not yet
769 expect(matchElement.children[0].children[1]).toBe(undefined);
770
771 /*
772 var info = matchClass.create(matchElement).info();
773 info.showTable();
774 */
775 var matchObj = matchClass.create(matchElement);
776 matchObj.open();
777
778 // Match
779 expect(matchElement.children[0].tagName).toEqual('DIV');
780
781 // snippet
782 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
783
784 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
785
786 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
787
788 // reference
789
790 expect(matchElement.children[2].classList.contains('ref')).toBeTruthy();
791 expect(matchElement.children[2].childNodes[1].nodeValue).toEqual('me');
792
793 // Add table
794 matchObj.panel.addTable();
795
796 // now
797 var infotable = matchElement.children[1];
798 expect(infotable.tagName).toEqual('DIV');
799
800 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
801
802 expect(infotable.firstChild.firstChild.firstChild.classList.contains('matchtable')).toBeTruthy();
803
804 // expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
805 });
806
807 it('should parse into a table view with all non-latin characters (sync)', function () {
808
809 // Override getMatchInfo API call
810 KorAP.API.getMatchInfo = function (x, param, cb) {
811 cb({ "snippet": snippetDiffToken });
812 };
813
814 var matchElement = matchElementFactory();
815 expect(matchElement.tagName).toEqual('LI');
816
817 // Match
818 expect(matchElement.children[0].tagName).toEqual('DIV');
819
820 var matchObj = matchClass.create(matchElement);
821 matchObj.open();
822
823 // Match
824 expect(matchElement.children[0].tagName).toEqual('DIV');
825
826 // snippet
827 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
828
829 // Add table
830 matchObj.panel.addTable();
831
832 // now
833 var infotable = matchElement.children[1];
834 expect(infotable.tagName).toEqual('DIV');
835
836 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
837
838 expect(infotable.firstChild.firstChild.firstChild.classList.contains('matchtable')).toBeTruthy();
839
840 let matchTable = infotable.firstChild.firstChild.firstChild;
841 expect(matchTable.querySelectorAll("th:not(.cutted).no-anno")[0].textContent).toEqual('Außerdem ');
842 expect(matchTable.getElementsByTagName('TH')[4].textContent).toEqual('Диес');
843 expect(matchTable.querySelectorAll("tbody tr:nth-child(1) td")[0].classList.contains('not-empty')).toBeFalsy();
844 expect(matchTable.querySelectorAll("tbody tr:nth-child(1) td")[1].classList.contains('not-empty')).toBeFalsy();
845 expect(matchTable.querySelectorAll("tbody tr:nth-child(1) td")[2].classList.contains('not-empty')).toBeFalsy();
846 expect(matchTable.querySelectorAll("tbody tr:nth-child(5) td")[0].classList.contains('not-empty')).toBeFalsy();
847 expect(matchTable.querySelectorAll("tbody tr:nth-child(5) td")[1].classList.contains('not-empty')).toBeFalsy();
848 expect(matchTable.querySelectorAll("tbody tr:nth-child(5) td")[2].classList.contains('not-empty')).toBeTruthy();
849 });
850
Nils Diewald58141332015-04-07 16:18:45 +0000851 });
Nils Diewalda297f062015-04-02 00:23:46 +0000852
Akron7f9a6a32018-07-18 15:05:23 +0200853 describe('KorAP.RelationsView', function () {
Akrond8692de2018-07-26 13:06:01 +0200854 beforeAll(beforeAllFunc);
855 afterAll(afterAllFunc);
856
Nils Diewald7c8ced22015-04-15 19:21:00 +0000857 var tree;
Nils Diewalda297f062015-04-02 00:23:46 +0000858
Nils Diewald7c8ced22015-04-15 19:21:00 +0000859 it('should be rendered async 1', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200860 var matchObj = matchClass.create(match);
861 var relObj = relClass.create(matchObj);
862 expect(relObj).toBeTruthy();
863 relObj.getData(undefined, undefined, "spans", function (y) {
Akron671fdb92017-09-12 18:09:46 +0200864 tree = y;
865 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000866 });
867 });
Nils Diewalda297f062015-04-02 00:23:46 +0000868
Nils Diewald7c8ced22015-04-15 19:21:00 +0000869 it('should be rendered async 2', function () {
Akron7f9a6a32018-07-18 15:05:23 +0200870 expect(tree).toBeTruthy();
871 expect(tree.nodes()).toEqual(49);
872
Nils Diewald7c8ced22015-04-15 19:21:00 +0000873 var e = tree.element();
874 expect(e.nodeName).toEqual('svg');
875 expect(e.getElementsByTagName('g').length).toEqual(48);
Nils Diewald58141332015-04-07 16:18:45 +0000876 });
Akron7f9a6a32018-07-18 15:05:23 +0200877
878
879 it('should add a tree view async 2', function () {
880 var matchElement = matchElementFactory();
881 var matchObj = matchClass.create(matchElement);
882 matchObj.open();
883 matchObj.panel.addTree('mate', 'beebop', 'spans', function () {
884 done();
885 });
886
887 // With added tree
888 var tree = matchElement.children[1].firstChild.firstChild.firstChild;
889 expect(tree.tagName).toEqual('DIV');
890 expect(tree.classList.contains('matchtree')).toBeTruthy();
891 expect(tree.children[0].tagName).toEqual('H6');
892 expect(tree.children[0].children[0].tagName).toEqual('SPAN');
893 expect(tree.children[0].children[0].firstChild.nodeValue).toEqual('mate');
894 expect(tree.children[0].children[1].tagName).toEqual('SPAN');
895 expect(tree.children[0].children[1].firstChild.nodeValue).toEqual('beebop');
896
897 expect(tree.children[1].tagName).toEqual('DIV');
898 });
899
Akron3bdac532019-03-04 13:24:43 +0100900 it('should make the tree downloadable', function () {
901 var treeClass = matchHierClass.create(treeSnippetHierarchy);
902 var treeElement = treeClass.element();
903 expect(treeElement.tagName).toEqual("svg");
904
905 var base64 = treeClass.toBase64();
906 var str = atob(base64);
907 expect(str).toMatch(new RegExp('<defs><style>path'));
908 expect(str).not.toMatch(new RegExp('&nbsp;'));
909 expect(str).toMatch(new RegExp('&amp;'));
910 });
Nils Diewald58141332015-04-07 16:18:45 +0000911 });
Nils Diewalda297f062015-04-02 00:23:46 +0000912
Nils Diewald7c8ced22015-04-15 19:21:00 +0000913
914 describe('KorAP.MatchTreeItem', function () {
Akrond8692de2018-07-26 13:06:01 +0200915 beforeAll(beforeAllFunc);
916 afterAll(afterAllFunc);
917
Nils Diewald7c8ced22015-04-15 19:21:00 +0000918 it('should be initializable', function () {
919 var mi = matchTreeItemClass.create(['cnx/c', 'cnx', 'c'])
920 expect(mi.element().firstChild.nodeValue).toEqual('cnx/c');
921 expect(mi.lcField()).toEqual(' cnx/c');
922 expect(mi.foundry()).toEqual('cnx');
923 expect(mi.layer()).toEqual('c');
924 });
Nils Diewalda297f062015-04-02 00:23:46 +0000925 });
Nils Diewalda297f062015-04-02 00:23:46 +0000926
927
Akron671fdb92017-09-12 18:09:46 +0200928 describe('KorAP.MatchRelation', function () {
Akrond8692de2018-07-26 13:06:01 +0200929 beforeAll(beforeAllFunc);
930 afterAll(afterAllFunc);
Akron671fdb92017-09-12 18:09:46 +0200931
932 var relExample = "<span class=\"context-left\"></span>" +
933 "<span class=\"match\">" +
934 " <span xml:id=\"token-GOE/AGA/01784-p199\">" +
935 " <span xlink:title=\"malt/d:ADV\" " +
936 " xlink:type=\"simple\" " +
937 " xlink:href=\"#token-GOE/AGA/01784-p199\">dann</span>" +
938 " </span>" +
939 " zog " +
940 " <span xlink:title=\"malt/d:SUBJ\" " +
941 " xlink:type=\"simple\" " +
942 " xlink:href=\"#token-GOE/AGA/01784-p199\">ich</span>" +
943 " <span xml:id=\"token-GOE/AGA/01784-p202\">" +
944 " <span xlink:title=\"malt/d:OBJA\" " +
945 " xlink:type=\"simple\" " +
946 " xlink:href=\"#token-GOE/AGA/01784-p199\">mich</span>" +
947 " </span>" +
948 "</span>" +
949 "<span class=\"context-right\"></span>";
950
951
952 it('should be initializable', function () {
Akrond8692de2018-07-26 13:06:01 +0200953 var tree = matchRelClass.create();
Akron671fdb92017-09-12 18:09:46 +0200954 expect(tree.size()).toBe(0);
955 });
956
957 it('should be parse string data', function () {
Akrond8692de2018-07-26 13:06:01 +0200958 var tree = matchRelClass.create(relExample);
Akron671fdb92017-09-12 18:09:46 +0200959 expect(tree.size()).toBe(4);
960 });
Akron0a785d42020-10-12 17:21:46 +0200961
962 it('should accept missing data', function () {
963 var relExample2 = "<span class=\"context-left\"><\/span>"+
964 "<span class=\"match\">"+
965 "{{"+
966 "<span xml:id=\"token-WUD17\/D95\/09441-p180\">"+
967 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p179\">Wikiläum<\/span>"+
968 "<\/span>"+
969 "|"+
970 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p180\">Silber<\/span>"+
971 "|"+
972 "<span xlink:title=\"malt\/d:DET\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p183\">Dein<\/span>"+
973 " "+
974 "<span xml:id=\"token-WUD17\/D95\/09441-p183\">"+
975 "<span xlink:title=\"malt\/d:ROOT\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p179-196\">Freund<\/span>"+
976 "<\/span>"+
977 " "+
978 "<span xlink:title=\"malt\/d:DET\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p185\">der<\/span>"+
979 " "+
980 "<span xml:id=\"token-WUD17\/D95\/09441-p185-186\">"+
981 "<span xml:id=\"token-WUD17\/D95\/09441-p185\">"+
982 "<mark>"+
983 "<span xlink:title=\"malt\/d:GMOD\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p183\">Baum<\/span>"+
984 "<\/mark>"+
985 "<\/span>"+
986 "| "+
987 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p185-186\">09:38<\/span>"+
988 "<\/span>"+
989 ", "+
990 "<span xlink:title=\"malt\/d:ATTR\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p188\">22.<\/span>"+
991 " "+
992 "<span xml:id=\"token-WUD17\/D95\/09441-p188\">"+
993 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p183\">Aug.<\/span>"+
994 "<\/span>"+
995 " "+
996 "<span xml:id=\"token-WUD17\/D95\/09441-p189\">"+
997 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p188\">2015<\/span>"+
998 "<\/span>"+
999 " ("+
1000 "<span xlink:title=\"malt\/d:PAR\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p189\">CEST<\/span>"+
1001 ")"+
1002 "<\/span>"+
1003 "<span class=\"context-right\"><\/span>";
1004 var tree = matchRelClass.create(relExample2);
1005 expect(tree.size()).toBe(18);
1006 var treeElement = tree.element();
1007 expect(treeElement.tagName).toEqual("svg");
1008 tree.show();
1009 expect(treeElement.querySelector("text[text-anchor=\"middle\"]").textContent).toEqual("APP");
1010 });
Akron671fdb92017-09-12 18:09:46 +02001011 });
1012
1013
Nils Diewald7c8ced22015-04-15 19:21:00 +00001014 describe('KorAP.MatchTreeMenu', function () {
Akrond8692de2018-07-26 13:06:01 +02001015 beforeAll(beforeAllFunc);
1016 afterAll(afterAllFunc);
Nils Diewald7c8ced22015-04-15 19:21:00 +00001017
1018 it('should be initializable', function () {
Akrond8692de2018-07-26 13:06:01 +02001019 var menu = matchTreeMenuClass.create([
Akron671fdb92017-09-12 18:09:46 +02001020 ['cnx/c', 'cnx', 'c'],
1021 ['xip/c', 'xip', 'c']
Akrond8692de2018-07-26 13:06:01 +02001022 ], matchTreeItemClass);
Nils Diewald7c8ced22015-04-15 19:21:00 +00001023
Akrond8692de2018-07-26 13:06:01 +02001024 expect(menu.itemClass()).toEqual(matchTreeItemClass);
Nils Diewald7c8ced22015-04-15 19:21:00 +00001025 expect(menu.element().nodeName).toEqual('UL');
Akronaba7a5a2016-08-15 21:58:33 +02001026 expect(menu.element().classList.contains('visible')).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001027 expect(menu.limit()).toEqual(6);
1028 menu.show();
Akronaba7a5a2016-08-15 21:58:33 +02001029 expect(menu.element().classList.contains('visible')).toBeTruthy();
Akronc1457bf2015-06-11 19:24:00 +02001030 expect(menu.item(0).active()).toBe(false);
Nils Diewald7c8ced22015-04-15 19:21:00 +00001031 });
Nils Diewalda297f062015-04-02 00:23:46 +00001032 });
hebasta999d6c12018-04-23 12:44:59 +02001033
1034 //Test display and sorting of meta information
1035 describe('KorAP.Meta', function(){
Akrond8692de2018-07-26 13:06:01 +02001036 beforeAll(beforeAllFunc);
1037 afterAll(afterAllFunc);
1038
1039 var met = metaClass.create(match, fields);
hebasta999d6c12018-04-23 12:44:59 +02001040 var mel = met.element();
1041
1042 // Meta information should be parsed into a list
1043 it('should parse in a meta view', function(){
Akronfa32c9d2018-11-20 15:39:18 +01001044 expect(mel.tagName).toEqual('DL');
1045 expect(mel.children[0].tagName).toEqual('DIV');
1046 expect(mel.children[0].children[0].tagName).toEqual('DT');
1047 expect(mel.children[0].children[0].attributes[0].name).toEqual('title');
1048 expect(mel.children[0].children[1].tagName).toEqual('DD');
1049 expect(mel.children[0].children[1].getAttribute('data-type')).toEqual('type:text')
hebasta999d6c12018-04-23 12:44:59 +02001050
Akronfa32c9d2018-11-20 15:39:18 +01001051 expect(mel.children[0].children[0].firstChild.nodeValue).toEqual('author');
1052 expect(mel.children[0].children[1].firstChild.nodeValue).toEqual('Sprachpfleger, u.a.');
1053 expect(mel.children[0].children[0].attributes[0].value).toEqual('author');
hebasta999d6c12018-04-23 12:44:59 +02001054 });
1055
1056
Akronfa32c9d2018-11-20 15:39:18 +01001057 /* The keywords in the meta information list should be formatted to be able
1058 to chose each keyword separately in the corpusByMatch assistant. */
1059 it('keywords should be formatted', function(){
hebasta999d6c12018-04-23 12:44:59 +02001060
Akronfa32c9d2018-11-20 15:39:18 +01001061 //type:string or type:keyword should b not relevant
1062 expect(mel.children[1].children[1].getAttribute('data-type')).toEqual('type:string')
1063 expect(mel.children[1].children[1].classList.contains('metakeyvalues')).toBeTruthy;
1064 expect(mel.children[1].children[1].children[0].tagName).toEqual('DIV');
1065 expect(mel.children[1].children[1].children[0].firstChild.nodeValue).toEqual('corenlp');
1066 expect(mel.children[1].children[1].children[1].tagName).toEqual('DIV');
1067 expect(mel.children[1].children[1].children[1].firstChild.nodeValue).toEqual('corenlp\/constituency');
1068
1069 expect(mel.children[2].children[1].classList.contains('metakeyvalues')).toBeTruthy;
1070 expect(mel.children[2].children[1].children[0].tagName).toEqual('DIV');
1071 expect(mel.children[2].children[1].children[0].firstChild.nodeValue).toEqual('kultur');
1072 expect(mel.children[2].children[1].children[1].tagName).toEqual('DIV');
1073 expect(mel.children[2].children[1].children[1].firstChild.nodeValue).toEqual('film');
hebasta999d6c12018-04-23 12:44:59 +02001074 });
Akrona0ea3c32018-12-14 18:33:48 +01001075
1076 it('attachements should be formatted', function(){
Akron0f700762022-01-11 17:21:16 +01001077 //type:attachement with a link (legacy)
Akrona0ea3c32018-12-14 18:33:48 +01001078 expect(mel.children[3].children[1].getAttribute('data-type')).toEqual('type:attachement')
Akron0f700762022-01-11 17:21:16 +01001079 expect(mel.children[3].children[1].classList.contains('metakeyvalues')).toBeFalsy;
1080 expect(mel.children[3].children[0].firstChild.nodeValue).toEqual('xlink');
1081 expect(mel.children[3].children[1].firstChild.textContent).toEqual('Cool');
1082 expect(mel.children[3].children[1].firstChild.tagName).toEqual('A');
Akrona0ea3c32018-12-14 18:33:48 +01001083 expect(mel.children[3].children[1].firstChild.getAttribute('href')).toEqual('https://de.wikipedia.org/wiki/Beispiel');
Akrond3bb85b2019-02-08 10:15:13 +01001084
Akron0f700762022-01-11 17:21:16 +01001085 //type:attachement with a link (uri encoded)
Akrond3bb85b2019-02-08 10:15:13 +01001086 expect(mel.children[4].children[1].getAttribute('data-type')).toEqual('type:attachement')
Akron0f700762022-01-11 17:21:16 +01001087 expect(mel.children[4].children[1].classList.contains('metakeyvalues')).toBeFalsy;
1088 expect(mel.children[4].children[0].firstChild.nodeValue).toEqual('xlink2');
1089 expect(mel.children[4].children[1].firstChild.textContent).toEqual('Hallo!');
1090 expect(mel.children[4].children[1].firstChild.tagName).toEqual('A');
1091 expect(mel.children[4].children[1].firstChild.getAttribute('href')).toEqual('https://www.test.de');
Akrond7d3ceb2022-02-07 20:13:09 +01001092
Akron0f700762022-01-11 17:21:16 +01001093 //type:attachement with plain text
1094 expect(mel.children[5].children[1].getAttribute('data-type')).toEqual('type:attachement')
1095 expect(mel.children[5].children[1].classList.contains('metakeyvalues')).toBeFalsy;
Akrond7d3ceb2022-02-07 20:13:09 +01001096 expect(mel.children[5].children[0].firstChild.nodeValue).toEqual('xlink3');
1097 expect(mel.children[5].children[1].firstChild.nodeValue).toEqual('[INVALID URI]');
1098
1099 //type:attachement with plain text
1100 expect(mel.children[6].children[1].getAttribute('data-type')).toEqual('type:attachement')
1101 expect(mel.children[6].children[1].classList.contains('metakeyvalues')).toBeFalsy;
1102 expect(mel.children[6].children[0].firstChild.nodeValue).toEqual('z-reference');
1103 expect(mel.children[6].children[1].firstChild.nodeValue).toEqual('This is a reference');
Akrond3bb85b2019-02-08 10:15:13 +01001104 });
Akrone3b566d2026-03-05 17:40:10 +01001105
1106 it('should mark metadata not in index', function () {
1107 let notInIndexField = Array.from(mel.children).find(function (field) {
1108 return field.children[0].firstChild.nodeValue === 'zz-notinindex';
1109 });
1110
1111 expect(notInIndexField).toBeTruthy();
1112 expect(notInIndexField.children[1].classList.contains('notinindex')).toBeTruthy();
1113 expect(notInIndexField.children[1].firstChild.nodeValue).toEqual('Stored but not indexed');
1114 });
Akrona0ea3c32018-12-14 18:33:48 +01001115
1116
hebasta999d6c12018-04-23 12:44:59 +02001117
Akronfa32c9d2018-11-20 15:39:18 +01001118 // Meta information should be sorted alphabetically
1119 it('should be alphabetically sorted', function(){
1120 var a = mel.children[0].children[0].firstChild.nodeValue;
1121 var b = mel.children[1].children[0].firstChild.nodeValue;
1122 var c = mel.children[2].children[0].firstChild.nodeValue;
1123 expect(a.localeCompare(b)).toBe(-1);
1124 expect(b.localeCompare(c)).toBe(-1);
Akrona0ea3c32018-12-14 18:33:48 +01001125 });
1126
1127
1128 it('should handle attachements', function () {
1129 let uri = attachementClass.create("data:text/plain;title=new,Hallo");
1130 expect(uri.contentType).toEqual("text/plain");
1131
1132 expect(uri.payload).toEqual("Hallo");
1133 expect(uri.base64).toBeFalsy();
1134 expect(uri.isLink).toBeFalsy();
1135 expect(uri.param["title"]).toEqual("new");
1136
1137 uri = attachementClass.create("data:application/x.korap-link,https://de.wikipedia.org/wiki/Beispiel");
1138 expect(uri.contentType).toEqual("application/x.korap-link");
1139 expect(uri.payload).toEqual("https://de.wikipedia.org/wiki/Beispiel");
1140 expect(uri.base64).toBeFalsy();
1141 expect(uri.isLink).toBeTruthy();
1142 expect(uri.inline().textContent).toEqual("https://de.wikipedia.org/wiki/Beispiel");
1143 expect(uri.inline().nodeType).toEqual(1);
1144 expect(uri.inline().tagName).toEqual("A");
1145 expect(uri.inline().getAttribute("rel")).toEqual("noopener noreferrer");
1146
1147
1148 uri = attachementClass.create("data:application/x.korap-link;title=Das ist ein Titel,https://de.wikipedia.org/wiki/Beispiel");
1149 expect(uri.contentType).toEqual("application/x.korap-link");
1150 expect(uri.payload).toEqual("https://de.wikipedia.org/wiki/Beispiel");
1151 expect(uri.base64).toBeFalsy();
1152 expect(uri.isLink).toBeTruthy();
1153 expect(uri.inline().textContent).toEqual("Das ist ein Titel");
1154 expect(uri.inline().nodeType).toEqual(1);
1155 expect(uri.inline().tagName).toEqual("A");
1156 expect(uri.inline().getAttribute("rel")).toEqual("noopener noreferrer");
1157
1158
1159 uri = attachementClass.create("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D");
1160 expect(uri.contentType).toEqual("text/plain");
1161 expect(uri.payload).toEqual("Hello, World!");
1162 expect(uri.base64).toBeTruthy();
1163 expect(uri.isLink).toBeFalsy();
1164 expect(uri.inline().nodeType).toEqual(3);
1165 expect(uri.inline().textContent).toEqual("Hello, World!");
1166
1167 uri = attachementClass.create("data:text/plain;title= new ; subTitle = old ;base64,SGVsbG8sIFdvcmxkIQ%3D%3D");
1168 expect(uri.contentType).toEqual("text/plain");
1169 expect(uri.payload).toEqual("Hello, World!");
1170 expect(uri.param["title"]).toEqual("new");
1171 expect(uri.param["subTitle"]).toEqual("old");
1172 expect(uri.base64).toBeTruthy();
1173 expect(uri.isLink).toBeFalsy();
1174 expect(uri.inline().nodeType).toEqual(3);
1175 expect(uri.inline().textContent).toEqual("Hello, World!");
1176 });
hebasta999d6c12018-04-23 12:44:59 +02001177 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001178 // table = view.toTable();
1179 // table.sortBy('');
1180 // table.element();
1181 // tree = view.toTree();
1182 // tree.element();
Nils Diewalda297f062015-04-02 00:23:46 +00001183});