blob: effe8d4245bc58743dd38e7460f04a9475e39ff9 [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
Akron3bdac532019-03-04 13:24:43 +0100225 var treeSnippetHierarchy =
226 "<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 +0200227
Akron158fce12019-12-17 14:43:29 +0100228 function matchElementFactory () {
Akrond8692de2018-07-26 13:06:01 +0200229 var me = document.createElement('li');
230
231 me.setAttribute(
232 'data-available-info',
233 'base/s=spans corenlp/c=spans corenlp/ne=tokens corenlp/p=tokens' +
234 ' corenlp/s=spans glemm/l=tokens mate/l=tokens mate/m=tokens' +
235 ' mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens' +
236 ' tt/p=tokens tt/s=spans');
237
238 me.setAttribute('data-corpus-id', 'WPD');
239 me.setAttribute('data-doc-id', 'FFF');
240 me.setAttribute('data-text-id', '01460');
241 me.setAttribute('data-text-sigle', 'WPD/FFF/01460');
242 me.setAttribute('data-match-id', 'p119-120');
243 me.innerHTML = '<div><div class="snippet">check</div></div><p class="ref">me</p>';
244 return me;
245 };
246
247 function matchElementReal () {
248 var me = document.createElement('em');
249 me.innerHTML =
250 '<li data-match-id="p85183-85184"' +
251 ' data-text-sigle="GOE/AGI/00000"' +
252 ' 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"' +
253 ' 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;}"' +
254 ' id="GOE/AGI/00000#p85183-85184">' +
255 '<div>' +
256 '<div class="flag"></div>' +
257 '<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>' +
258 '</div>' +
259 '<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>' +
260 '</li>';
261 return me.firstChild;
262 };
263
264 var beforeAllFunc = function () {
265 // Override getMatchInfo API call
266 KorAP.API.getMatchInfo = function (x, param, cb) {
267 if (param['spans'] === undefined || param['spans'] === false)
268 cb({ "snippet": snippet });
269 else
270 cb({ "snippet": treeSnippet });
271 };
272 };
273
274 var afterAllFunc = function () {
275 KorAP.API.getMatchInfo = undefined;
hebasta87f1b1f2019-07-30 13:03:23 +0200276 KorAP.TreeMenu = undefined;
Akrond8692de2018-07-26 13:06:01 +0200277 var body = document.body;
hebasta87f1b1f2019-07-30 13:03:23 +0200278 var i = body.children.length - 1;
279 while (i >= 0) {
Akrond8692de2018-07-26 13:06:01 +0200280 if (body.children[i].nodeType && body.children[i].nodeType === 1) {
281 if (!body.children[i].classList.contains("jasmine_html-reporter")) {
282 body.removeChild(body.children[i]);
283 };
284 };
hebasta87f1b1f2019-07-30 13:03:23 +0200285 i--;
Akrond8692de2018-07-26 13:06:01 +0200286 };
287 };
Akron671fdb92017-09-12 18:09:46 +0200288
Nils Diewald7c8ced22015-04-15 19:21:00 +0000289 describe('KorAP.InfoLayer', function () {
Akrond8692de2018-07-26 13:06:01 +0200290 beforeAll(beforeAllFunc);
291 afterAll(afterAllFunc);
Nils Diewalda297f062015-04-02 00:23:46 +0000292
Nils Diewald7c8ced22015-04-15 19:21:00 +0000293 it('should be initializable', function () {
294 expect(
Akron671fdb92017-09-12 18:09:46 +0200295 function() { infoClass.create() }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000296 ).toThrow(new Error("Missing parameters"));
Nils Diewalda297f062015-04-02 00:23:46 +0000297
Nils Diewald7c8ced22015-04-15 19:21:00 +0000298 expect(
Akron671fdb92017-09-12 18:09:46 +0200299 function() { infoClass.create("base") }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000300 ).toThrow(new Error("Missing parameters"));
Nils Diewalda297f062015-04-02 00:23:46 +0000301
Nils Diewald7c8ced22015-04-15 19:21:00 +0000302 var layer = infoClass.create("base", "s");
303 expect(layer).toBeTruthy();
304 expect(layer.foundry).toEqual("base");
305 expect(layer.layer).toEqual("s");
306 expect(layer.type).toEqual("tokens");
Nils Diewalda297f062015-04-02 00:23:46 +0000307
Nils Diewald7c8ced22015-04-15 19:21:00 +0000308 layer = infoClass.create("cnx", "syn", "spans");
309 expect(layer).toBeTruthy();
310 expect(layer.foundry).toEqual("cnx");
311 expect(layer.layer).toEqual("syn");
312 expect(layer.type).toEqual("spans");
Nils Diewald58141332015-04-07 16:18:45 +0000313 });
314 });
Nils Diewalda297f062015-04-02 00:23:46 +0000315
Nils Diewalda297f062015-04-02 00:23:46 +0000316
Nils Diewald7c8ced22015-04-15 19:21:00 +0000317 describe('KorAP.Match', function () {
Akrond8692de2018-07-26 13:06:01 +0200318 beforeAll(beforeAllFunc);
319 afterAll(afterAllFunc);
320
Nils Diewald7c8ced22015-04-15 19:21:00 +0000321 var match = {
322 'corpusID' : 'WPD',
323 'docID' : 'UUU',
324 'textID' : '01912',
325 'matchID' : 'p121-122',
Akron0a6768f2016-07-13 18:00:43 +0200326 'textSigle' : 'WPD/UUU/01912',
Nils Diewald7c8ced22015-04-15 19:21:00 +0000327 'available' : available
328 };
329
Nils Diewald7c8ced22015-04-15 19:21:00 +0000330 it('should be initializable by Object', function () {
331 expect(function() {
Akron671fdb92017-09-12 18:09:46 +0200332 matchClass.create()
Nils Diewald7c8ced22015-04-15 19:21:00 +0000333 }).toThrow(new Error('Missing parameters'));
334
335 expect(matchClass.create(match)).toBeTruthy();
336
337 var m = matchClass.create(match);
Akron0a6768f2016-07-13 18:00:43 +0200338 expect(m.textSigle).toEqual("WPD/UUU/01912");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000339 expect(m.matchID).toEqual("p121-122");
340
341 // /corpus/WPD/UUU.01912/p121-122/matchInfo?spans=false&foundry=*
342 var m = matchClass.create(match);
343
344 // Spans:
345 var spans = m.getSpans();
346 expect(spans[0].foundry).toEqual("base");
347 expect(spans[0].layer).toEqual("s");
348
349 expect(spans[1].foundry).toEqual("corenlp");
350 expect(spans[1].layer).toEqual("c");
351
352 expect(spans[2].foundry).toEqual("corenlp");
353 expect(spans[2].layer).toEqual("s");
354
355 expect(spans[spans.length-1].foundry).toEqual("tt");
356 expect(spans[spans.length-1].layer).toEqual("s");
357
358 // Tokens:
359 var tokens = m.getTokens();
360 expect(tokens[0].foundry).toEqual("corenlp");
361 expect(tokens[0].layer).toEqual("ne");
362
363 expect(tokens[1].foundry).toEqual("corenlp");
364 expect(tokens[1].layer).toEqual("p");
365
366 expect(tokens[tokens.length-1].foundry).toEqual("tt");
367 expect(tokens[tokens.length-1].layer).toEqual("p");
Nils Diewald58141332015-04-07 16:18:45 +0000368 });
Nils Diewalda297f062015-04-02 00:23:46 +0000369
370
Akroncdb0baa2016-11-07 01:52:11 +0100371 it('should be initializable by Node 1', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000372 var m = matchClass.create(matchElementFactory());
Akron0a6768f2016-07-13 18:00:43 +0200373 expect(m.textSigle).toEqual("WPD/FFF/01460");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000374 expect(m.matchID).toEqual("p119-120");
Nils Diewalda297f062015-04-02 00:23:46 +0000375
Nils Diewald7c8ced22015-04-15 19:21:00 +0000376 // Spans:
377 var spans = m.getSpans();
378 expect(spans[0].foundry).toEqual("base");
379 expect(spans[0].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000380
Nils Diewald7c8ced22015-04-15 19:21:00 +0000381 expect(spans[1].foundry).toEqual("corenlp");
382 expect(spans[1].layer).toEqual("c");
Nils Diewalda297f062015-04-02 00:23:46 +0000383
Nils Diewald7c8ced22015-04-15 19:21:00 +0000384 expect(spans[2].foundry).toEqual("corenlp");
385 expect(spans[2].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000386
Nils Diewald7c8ced22015-04-15 19:21:00 +0000387 expect(spans[spans.length-1].foundry).toEqual("tt");
388 expect(spans[spans.length-1].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000389
Nils Diewald7c8ced22015-04-15 19:21:00 +0000390 // Tokens:
391 var tokens = m.getTokens();
392 expect(tokens[0].foundry).toEqual("corenlp");
393 expect(tokens[0].layer).toEqual("ne");
Nils Diewalda297f062015-04-02 00:23:46 +0000394
Nils Diewald7c8ced22015-04-15 19:21:00 +0000395 expect(tokens[1].foundry).toEqual("corenlp");
396 expect(tokens[1].layer).toEqual("p");
Nils Diewalda297f062015-04-02 00:23:46 +0000397
Nils Diewald7c8ced22015-04-15 19:21:00 +0000398 expect(tokens[tokens.length-1].foundry).toEqual("tt");
399 expect(tokens[tokens.length-1].layer).toEqual("p");
Nils Diewalda297f062015-04-02 00:23:46 +0000400
Nils Diewald7c8ced22015-04-15 19:21:00 +0000401 });
Nils Diewalda297f062015-04-02 00:23:46 +0000402
Akroncdb0baa2016-11-07 01:52:11 +0100403 it('should be initializable by Node 2', function () {
404 var ele = matchElementReal();
405 var m = matchClass.create(ele);
406 expect(m.textSigle).toEqual("GOE/AGI/00000");
407 expect(m.matchID).toEqual("p85183-85184");
408 });
409
Akron3c390c42020-03-30 09:06:21 +0200410 it('should be initializable when active', function () {
411 var e = matchElementFactory();
412 e.setAttribute('class', 'active');
413
414 expect(e.classList.contains('active')).toBe(true);
415 expect(e["_match"]).toBe(undefined);
416
417 var m = matchClass.create(e);
418
419 expect(e["_match"]).not.toBe(undefined);
420
421 // Open the match
422 m.init();
423
424 expect(e["_match"]).not.toBe(undefined);
425
426 actions = e.querySelector("p.ref > div.action.button-group").children;
427
428 expect(actions[0].getAttribute("class")).toEqual("metatable");
429 expect(actions[1].getAttribute("class")).toEqual("info");
430 expect(actions[2].getAttribute("class")).toEqual("tree");
431
432 // Close the match
433 expect(e.querySelector("div.action.button-group > span.minimize")).toBe(null);
434 });
Akroncdb0baa2016-11-07 01:52:11 +0100435
Nils Diewald7c8ced22015-04-15 19:21:00 +0000436 it('should react to gui actions', function () {
437 var e = matchElementFactory();
Nils Diewalda297f062015-04-02 00:23:46 +0000438
Nils Diewald7c8ced22015-04-15 19:21:00 +0000439 expect(e.classList.contains('active')).toBe(false);
440 expect(e["_match"]).toBe(undefined);
Nils Diewalda297f062015-04-02 00:23:46 +0000441
Nils Diewald7c8ced22015-04-15 19:21:00 +0000442 var m = matchClass.create(e);
443
444 expect(e.classList.contains('active')).toBe(false);
445 expect(e["_match"]).not.toBe(undefined);
hebasta87f1b1f2019-07-30 13:03:23 +0200446
Nils Diewald7c8ced22015-04-15 19:21:00 +0000447 // Open the match
448 m.open();
hebasta87f1b1f2019-07-30 13:03:23 +0200449
Nils Diewald7c8ced22015-04-15 19:21:00 +0000450 expect(e.classList.contains('active')).toBe(true);
451 expect(e["_match"]).not.toBe(undefined);
452
Akronbfe912c2018-07-17 19:30:52 +0200453 actions = e.querySelector("p.ref > div.action.button-group").children;
Akrond141a362018-07-10 18:12:13 +0200454
Akronbfe912c2018-07-17 19:30:52 +0200455 expect(actions[0].getAttribute("class")).toEqual("metatable");
Akronc296ca22018-04-24 16:35:26 +0200456 expect(actions[1].getAttribute("class")).toEqual("info");
457 expect(actions[2].getAttribute("class")).toEqual("tree");
Akron3c390c42020-03-30 09:06:21 +0200458
459 expect(e.querySelector("div.action.button-group > span.minimize")).not.toBe(null);
Akronc296ca22018-04-24 16:35:26 +0200460
Nils Diewald7c8ced22015-04-15 19:21:00 +0000461 // Close the match
Akronec6bb8e2018-08-29 13:07:56 +0200462 m.minimize();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000463 expect(e.classList.contains('active')).toBe(false);
464 expect(e["_match"]).not.toBe(undefined);
Nils Diewald58141332015-04-07 16:18:45 +0000465 });
Akrone57e8802020-10-17 08:23:45 +0200466
467 it('should toggle', function () {
468 var e = matchElementFactory();
469
470 expect(e.classList.contains('active')).toBe(false);
471 expect(e["_match"]).toBe(undefined);
472
473 var m = matchClass.create(e);
474
475 expect(e.classList.contains('active')).toBe(false);
476 expect(e["_match"]).not.toBe(undefined);
477
478 // Open the match
479 m.open();
480
481 expect(e.classList.contains('active')).toBe(true);
482 expect(e["_match"]).not.toBe(undefined);
483
484 m.toggle();
485
486 expect(e.classList.contains('active')).toBe(false);
487 expect(e["_match"]).not.toBe(undefined);
488
489 m.toggle();
490
491 expect(e.classList.contains('active')).toBe(true);
492 expect(e["_match"]).not.toBe(undefined);
493 });
494
Akrond8692de2018-07-26 13:06:01 +0200495 it('should open tree menu', function () {
Akronc296ca22018-04-24 16:35:26 +0200496 var e = matchElementFactory();
497 var m = matchClass.create(e);
498 m.open();
Akronbfe912c2018-07-17 19:30:52 +0200499 var relation = e.querySelector("p.ref > div.action.button-group > span:nth-of-type(3)");
Akronc296ca22018-04-24 16:35:26 +0200500 expect(relation.getAttribute("class")).toEqual("tree");
Akron52ed22d2018-07-11 17:05:19 +0200501 expect(document.getElementsByClassName("button-group-list").length).toEqual(0);
Akronc296ca22018-04-24 16:35:26 +0200502 expect(document.activeElement.tagName).toEqual("BODY");
hebasta87f1b1f2019-07-30 13:03:23 +0200503
Akronc296ca22018-04-24 16:35:26 +0200504 // Show menu
505 relation.click();
Akron52ed22d2018-07-11 17:05:19 +0200506 expect(document.getElementsByClassName("button-group-list").length).toEqual(1);
Akronc296ca22018-04-24 16:35:26 +0200507 expect(document.activeElement.tagName).toEqual("UL");
hebasta87f1b1f2019-07-30 13:03:23 +0200508
Akronc296ca22018-04-24 16:35:26 +0200509 // Choose first tree
Akron52ed22d2018-07-11 17:05:19 +0200510 document.getElementsByClassName("button-group-list")[0].getElementsByTagName("li")[1].click();
Akronc296ca22018-04-24 16:35:26 +0200511 expect(e.querySelector("div.matchinfo div.matchtree h6 span").innerText).toEqual("corenlp");
512
513 // This should blur the focus
514 expect(document.activeElement.tagName).toEqual("BODY");
hebasta87f1b1f2019-07-30 13:03:23 +0200515
Akronc296ca22018-04-24 16:35:26 +0200516 });
517
518 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000519
Akron7f9a6a32018-07-18 15:05:23 +0200520 describe('KorAP.TableView', function () {
Akrond8692de2018-07-26 13:06:01 +0200521 beforeAll(beforeAllFunc);
522 afterAll(afterAllFunc);
Akron5dc31172019-05-15 18:43:48 +0200523
524 let longString = " und robust sind auch die anderen Traktoren, die hier der Übersicht wegen keine Erwähnung finden können.";
525
Akron7f9a6a32018-07-18 15:05:23 +0200526 var table;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000527
Akron7f9a6a32018-07-18 15:05:23 +0200528 var matchObj = matchClass.create(match);
529 var tableObj = tableClass.create(matchObj);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000530
531 var table1, table2;
532
Nils Diewald7c8ced22015-04-15 19:21:00 +0000533 it('should fail to load a table async', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200534 expect(tableObj).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000535
Akron7f9a6a32018-07-18 15:05:23 +0200536 tableObj.getData([], function (tablen) {
Akron671fdb92017-09-12 18:09:46 +0200537 table1 = tablen;
538 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000539 });
540 });
541
Akron671fdb92017-09-12 18:09:46 +0200542
Akronaeeb8252018-09-19 18:51:00 +0200543 xit('should\'nt be parsable (async)', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000544 expect(table1).not.toBeTruthy();
545 });
546
Nils Diewald7c8ced22015-04-15 19:21:00 +0000547
Nils Diewald7c8ced22015-04-15 19:21:00 +0000548 it('should be retrieved async', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200549 expect(tableObj).toBeTruthy();
550 tableObj.getData(undefined, function (x) {
Akron671fdb92017-09-12 18:09:46 +0200551 table = x;
552 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000553 });
554 });
Nils Diewalda297f062015-04-02 00:23:46 +0000555
Akron7f9a6a32018-07-18 15:05:23 +0200556 it('should parse into a table (async)', function () {
557 expect(table).toBeTruthy();
Akron5b1a6af2018-02-05 15:41:16 +0100558
Akron158fce12019-12-17 14:43:29 +0100559 expect(table.length()).toBe(8);
Akron7f9a6a32018-07-18 15:05:23 +0200560
Akron1a780fe2019-05-21 15:59:00 +0200561 expect(table.getToken(0)).toBe("");
562 expect(table.getToken(1)).toBe("Außerdem ");
563 expect(table.getToken(2)).toBe("meist");
564 expect(table.getToken(3)).toBe("deutlich");
Akron158fce12019-12-17 14:43:29 +0100565 expect(table.getToken(5)).toBe("leistungsfähiger");
566 expect(table.getToken(6)).toBe(longString);
Akron7f9a6a32018-07-18 15:05:23 +0200567
Akron1a780fe2019-05-21 15:59:00 +0200568 expect(table.getValue(2, "cnx", "p")[0]).toBe("ADV");
569 expect(table.getValue(2, "cnx", "syn")[0]).toBe("@PREMOD");
570 expect(table.getValue(2, "mate", "l")[0]).toBe("meist");
571 expect(table.getValue(2, "mate", "l")[1]).toBeUndefined();
Akron7f9a6a32018-07-18 15:05:23 +0200572
Akron158fce12019-12-17 14:43:29 +0100573 expect(table.getValue(5, "cnx", "l")[0]).toBe("fähig");
574 expect(table.getValue(5, "cnx", "l")[1]).toBe("leistung");
Akron7f9a6a32018-07-18 15:05:23 +0200575 });
576
577 it('should be rendered async', function () {
Akron5b1a6af2018-02-05 15:41:16 +0100578 var e = table.element().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000579 expect(e.nodeName).toBe('TABLE');
580 expect(e.children[0].nodeName).toBe('THEAD');
581 var tr = e.children[0].children[0];
582 expect(tr.nodeName).toBe('TR');
583 expect(tr.children[0].nodeName).toBe('TH');
Nils Diewald58141332015-04-07 16:18:45 +0000584
Nils Diewald7c8ced22015-04-15 19:21:00 +0000585 expect(tr.children[0].firstChild.nodeValue).toBe('Foundry');
586 expect(tr.children[1].firstChild.nodeValue).toBe('Layer');
Akron1a780fe2019-05-21 15:59:00 +0200587
588 expect(tr.children[2].classList.contains('cutted')).toBeTruthy();
589 expect(tr.children[3].firstChild.nodeValue).toBe('Außerdem ');
590
591
592 expect(tr.children[4].firstChild.nodeValue).toBe('meist');
Akronad1e46a2018-09-19 15:55:40 +0200593 expect(tr.children[4].classList.contains('mark')).toBeFalsy();
Akron1a780fe2019-05-21 15:59:00 +0200594 expect(tr.children[5].firstChild.nodeValue).toBe('deutlich');
595 expect(tr.children[5].classList.contains('mark')).toBeTruthy();
Akron158fce12019-12-17 14:43:29 +0100596 expect(tr.children[6].firstChild.nodeValue).toBe('▮');
597 expect(tr.children[7].firstChild.nodeValue).toBe('leistungsfähiger');
598 expect(tr.children[7].classList.contains('mark')).toBeFalsy();
599 expect(tr.children[7].hasAttribute("title")).toBeFalsy();
600 expect(tr.children[8].firstChild.nodeValue).toBe(longString);
601 expect(tr.children[8].getAttribute("title")).toBe(longString);
602 expect(tr.children[9].classList.contains('cutted')).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000603
604 // first row
605 tr = e.children[1].children[0];
606 expect(tr.nodeName).toBe('TR');
607 expect(tr.getAttribute('tabindex')).toEqual('0');
608 expect(tr.children[0].nodeName).toBe('TH');
609 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
610 expect(tr.children[1].firstChild.nodeValue).toEqual('l');
Akron1a780fe2019-05-21 15:59:00 +0200611 expect(tr.children[4].firstChild.nodeValue).toEqual('meist');
612 expect(tr.children[5].firstChild.nodeValue).toEqual('deutlich');
Akron158fce12019-12-17 14:43:29 +0100613 expect(tr.children[6].firstChild).toBeNull();
614 expect(tr.children[7].firstChild.firstChild.nodeValue).toEqual('fähig');
615 expect(tr.children[7].lastChild.firstChild.nodeValue).toEqual('leistung');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000616
617 // second row
618 tr = e.children[1].children[1];
619 expect(tr.nodeName).toBe('TR');
620 expect(tr.getAttribute('tabindex')).toEqual('0');
621 expect(tr.children[0].nodeName).toBe('TH');
622 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
623 expect(tr.children[1].firstChild.nodeValue).toEqual('p');
Akron1a780fe2019-05-21 15:59:00 +0200624 expect(tr.children[4].firstChild.nodeValue).toEqual('ADV');
625 expect(tr.children[5].firstChild.nodeValue).toEqual('A');
Akron158fce12019-12-17 14:43:29 +0100626 expect(tr.children[6].firstChild).toBeNull();
627 expect(tr.children[7].firstChild.firstChild.nodeValue).toEqual('A');
628 expect(tr.children[7].lastChild.firstChild.nodeValue).toEqual('ADJA');
Akronf2279c42017-12-21 13:48:46 +0100629
Akron158fce12019-12-17 14:43:29 +0100630 expect(tr.children[7].firstChild.getAttribute("title")).toEqual('Adjective');
Akron1a780fe2019-05-21 15:59:00 +0200631 expect(tr.children[4].getAttribute("title")).toEqual('Adverb');
Nils Diewald58141332015-04-07 16:18:45 +0000632 });
Akron7f9a6a32018-07-18 15:05:23 +0200633
634
635 it('should parse into a table view (sync)', function () {
636 var matchElement = matchElementFactory();
637 expect(matchElement.tagName).toEqual('LI');
638
639 // Match
640 expect(matchElement.children[0].tagName).toEqual('DIV');
641
642 // snippet
643 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
644 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
645 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
646
647 // reference
648 expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
649 expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
650
651 // not yet
652 expect(matchElement.children[0].children[1]).toBe(undefined);
653
654 /*
655 var info = matchClass.create(matchElement).info();
656 info.showTable();
657 */
658 var matchObj = matchClass.create(matchElement);
659 matchObj.open();
660
661 // Match
662 expect(matchElement.children[0].tagName).toEqual('DIV');
663
664 // snippet
665 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
666
667 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
668
669 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
670
671 // reference
672
673 expect(matchElement.children[2].classList.contains('ref')).toBeTruthy();
674 expect(matchElement.children[2].childNodes[1].nodeValue).toEqual('me');
675
676 // Add table
677 matchObj.panel.addTable();
678
679 // now
680 var infotable = matchElement.children[1];
681 expect(infotable.tagName).toEqual('DIV');
682
683 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
684
685 expect(infotable.firstChild.firstChild.firstChild.classList.contains('matchtable')).toBeTruthy();
686
687 // expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
688 });
689
Akron158fce12019-12-17 14:43:29 +0100690 it('should parse into a table view with non-verbal elements (sync)', function () {
691 var matchElement = matchElementFactory();
692 expect(matchElement.tagName).toEqual('LI');
693 });
694
Nils Diewald58141332015-04-07 16:18:45 +0000695 });
Nils Diewalda297f062015-04-02 00:23:46 +0000696
Akron7f9a6a32018-07-18 15:05:23 +0200697 describe('KorAP.RelationsView', function () {
Akrond8692de2018-07-26 13:06:01 +0200698 beforeAll(beforeAllFunc);
699 afterAll(afterAllFunc);
700
Nils Diewald7c8ced22015-04-15 19:21:00 +0000701 var tree;
Nils Diewalda297f062015-04-02 00:23:46 +0000702
Nils Diewald7c8ced22015-04-15 19:21:00 +0000703 it('should be rendered async 1', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200704 var matchObj = matchClass.create(match);
705 var relObj = relClass.create(matchObj);
706 expect(relObj).toBeTruthy();
707 relObj.getData(undefined, undefined, "spans", function (y) {
Akron671fdb92017-09-12 18:09:46 +0200708 tree = y;
709 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000710 });
711 });
Nils Diewalda297f062015-04-02 00:23:46 +0000712
Nils Diewald7c8ced22015-04-15 19:21:00 +0000713 it('should be rendered async 2', function () {
Akron7f9a6a32018-07-18 15:05:23 +0200714 expect(tree).toBeTruthy();
715 expect(tree.nodes()).toEqual(49);
716
Nils Diewald7c8ced22015-04-15 19:21:00 +0000717 var e = tree.element();
718 expect(e.nodeName).toEqual('svg');
719 expect(e.getElementsByTagName('g').length).toEqual(48);
Nils Diewald58141332015-04-07 16:18:45 +0000720 });
Akron7f9a6a32018-07-18 15:05:23 +0200721
722
723 it('should add a tree view async 2', function () {
724 var matchElement = matchElementFactory();
725 var matchObj = matchClass.create(matchElement);
726 matchObj.open();
727 matchObj.panel.addTree('mate', 'beebop', 'spans', function () {
728 done();
729 });
730
731 // With added tree
732 var tree = matchElement.children[1].firstChild.firstChild.firstChild;
733 expect(tree.tagName).toEqual('DIV');
734 expect(tree.classList.contains('matchtree')).toBeTruthy();
735 expect(tree.children[0].tagName).toEqual('H6');
736 expect(tree.children[0].children[0].tagName).toEqual('SPAN');
737 expect(tree.children[0].children[0].firstChild.nodeValue).toEqual('mate');
738 expect(tree.children[0].children[1].tagName).toEqual('SPAN');
739 expect(tree.children[0].children[1].firstChild.nodeValue).toEqual('beebop');
740
741 expect(tree.children[1].tagName).toEqual('DIV');
742 });
743
Akron3bdac532019-03-04 13:24:43 +0100744 it('should make the tree downloadable', function () {
745 var treeClass = matchHierClass.create(treeSnippetHierarchy);
746 var treeElement = treeClass.element();
747 expect(treeElement.tagName).toEqual("svg");
748
749 var base64 = treeClass.toBase64();
750 var str = atob(base64);
751 expect(str).toMatch(new RegExp('<defs><style>path'));
752 expect(str).not.toMatch(new RegExp('&nbsp;'));
753 expect(str).toMatch(new RegExp('&amp;'));
754 });
Nils Diewald58141332015-04-07 16:18:45 +0000755 });
Nils Diewalda297f062015-04-02 00:23:46 +0000756
Nils Diewald7c8ced22015-04-15 19:21:00 +0000757
758 describe('KorAP.MatchTreeItem', function () {
Akrond8692de2018-07-26 13:06:01 +0200759 beforeAll(beforeAllFunc);
760 afterAll(afterAllFunc);
761
Nils Diewald7c8ced22015-04-15 19:21:00 +0000762 it('should be initializable', function () {
763 var mi = matchTreeItemClass.create(['cnx/c', 'cnx', 'c'])
764 expect(mi.element().firstChild.nodeValue).toEqual('cnx/c');
765 expect(mi.lcField()).toEqual(' cnx/c');
766 expect(mi.foundry()).toEqual('cnx');
767 expect(mi.layer()).toEqual('c');
768 });
Nils Diewalda297f062015-04-02 00:23:46 +0000769 });
Nils Diewalda297f062015-04-02 00:23:46 +0000770
771
Akron671fdb92017-09-12 18:09:46 +0200772 describe('KorAP.MatchRelation', function () {
Akrond8692de2018-07-26 13:06:01 +0200773 beforeAll(beforeAllFunc);
774 afterAll(afterAllFunc);
Akron671fdb92017-09-12 18:09:46 +0200775
776 var relExample = "<span class=\"context-left\"></span>" +
777 "<span class=\"match\">" +
778 " <span xml:id=\"token-GOE/AGA/01784-p199\">" +
779 " <span xlink:title=\"malt/d:ADV\" " +
780 " xlink:type=\"simple\" " +
781 " xlink:href=\"#token-GOE/AGA/01784-p199\">dann</span>" +
782 " </span>" +
783 " zog " +
784 " <span xlink:title=\"malt/d:SUBJ\" " +
785 " xlink:type=\"simple\" " +
786 " xlink:href=\"#token-GOE/AGA/01784-p199\">ich</span>" +
787 " <span xml:id=\"token-GOE/AGA/01784-p202\">" +
788 " <span xlink:title=\"malt/d:OBJA\" " +
789 " xlink:type=\"simple\" " +
790 " xlink:href=\"#token-GOE/AGA/01784-p199\">mich</span>" +
791 " </span>" +
792 "</span>" +
793 "<span class=\"context-right\"></span>";
794
795
796 it('should be initializable', function () {
Akrond8692de2018-07-26 13:06:01 +0200797 var tree = matchRelClass.create();
Akron671fdb92017-09-12 18:09:46 +0200798 expect(tree.size()).toBe(0);
799 });
800
801 it('should be parse string data', function () {
Akrond8692de2018-07-26 13:06:01 +0200802 var tree = matchRelClass.create(relExample);
Akron671fdb92017-09-12 18:09:46 +0200803 expect(tree.size()).toBe(4);
804 });
Akron0a785d42020-10-12 17:21:46 +0200805
806 it('should accept missing data', function () {
807 var relExample2 = "<span class=\"context-left\"><\/span>"+
808 "<span class=\"match\">"+
809 "{{"+
810 "<span xml:id=\"token-WUD17\/D95\/09441-p180\">"+
811 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p179\">Wikiläum<\/span>"+
812 "<\/span>"+
813 "|"+
814 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p180\">Silber<\/span>"+
815 "|"+
816 "<span xlink:title=\"malt\/d:DET\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p183\">Dein<\/span>"+
817 " "+
818 "<span xml:id=\"token-WUD17\/D95\/09441-p183\">"+
819 "<span xlink:title=\"malt\/d:ROOT\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p179-196\">Freund<\/span>"+
820 "<\/span>"+
821 " "+
822 "<span xlink:title=\"malt\/d:DET\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p185\">der<\/span>"+
823 " "+
824 "<span xml:id=\"token-WUD17\/D95\/09441-p185-186\">"+
825 "<span xml:id=\"token-WUD17\/D95\/09441-p185\">"+
826 "<mark>"+
827 "<span xlink:title=\"malt\/d:GMOD\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p183\">Baum<\/span>"+
828 "<\/mark>"+
829 "<\/span>"+
830 "| "+
831 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p185-186\">09:38<\/span>"+
832 "<\/span>"+
833 ", "+
834 "<span xlink:title=\"malt\/d:ATTR\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p188\">22.<\/span>"+
835 " "+
836 "<span xml:id=\"token-WUD17\/D95\/09441-p188\">"+
837 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p183\">Aug.<\/span>"+
838 "<\/span>"+
839 " "+
840 "<span xml:id=\"token-WUD17\/D95\/09441-p189\">"+
841 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p188\">2015<\/span>"+
842 "<\/span>"+
843 " ("+
844 "<span xlink:title=\"malt\/d:PAR\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p189\">CEST<\/span>"+
845 ")"+
846 "<\/span>"+
847 "<span class=\"context-right\"><\/span>";
848 var tree = matchRelClass.create(relExample2);
849 expect(tree.size()).toBe(18);
850 var treeElement = tree.element();
851 expect(treeElement.tagName).toEqual("svg");
852 tree.show();
853 expect(treeElement.querySelector("text[text-anchor=\"middle\"]").textContent).toEqual("APP");
854 });
Akron671fdb92017-09-12 18:09:46 +0200855 });
856
857
Nils Diewald7c8ced22015-04-15 19:21:00 +0000858 describe('KorAP.MatchTreeMenu', function () {
Akrond8692de2018-07-26 13:06:01 +0200859 beforeAll(beforeAllFunc);
860 afterAll(afterAllFunc);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000861
862 it('should be initializable', function () {
Akrond8692de2018-07-26 13:06:01 +0200863 var menu = matchTreeMenuClass.create([
Akron671fdb92017-09-12 18:09:46 +0200864 ['cnx/c', 'cnx', 'c'],
865 ['xip/c', 'xip', 'c']
Akrond8692de2018-07-26 13:06:01 +0200866 ], matchTreeItemClass);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000867
Akrond8692de2018-07-26 13:06:01 +0200868 expect(menu.itemClass()).toEqual(matchTreeItemClass);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000869 expect(menu.element().nodeName).toEqual('UL');
Akronaba7a5a2016-08-15 21:58:33 +0200870 expect(menu.element().classList.contains('visible')).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000871 expect(menu.limit()).toEqual(6);
872 menu.show();
Akronaba7a5a2016-08-15 21:58:33 +0200873 expect(menu.element().classList.contains('visible')).toBeTruthy();
Akronc1457bf2015-06-11 19:24:00 +0200874 expect(menu.item(0).active()).toBe(false);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000875 });
Nils Diewalda297f062015-04-02 00:23:46 +0000876 });
hebasta999d6c12018-04-23 12:44:59 +0200877
878 //Test display and sorting of meta information
879 describe('KorAP.Meta', function(){
Akrond8692de2018-07-26 13:06:01 +0200880 beforeAll(beforeAllFunc);
881 afterAll(afterAllFunc);
882
883 var met = metaClass.create(match, fields);
hebasta999d6c12018-04-23 12:44:59 +0200884 var mel = met.element();
885
886 // Meta information should be parsed into a list
887 it('should parse in a meta view', function(){
Akronfa32c9d2018-11-20 15:39:18 +0100888 expect(mel.tagName).toEqual('DL');
889 expect(mel.children[0].tagName).toEqual('DIV');
890 expect(mel.children[0].children[0].tagName).toEqual('DT');
891 expect(mel.children[0].children[0].attributes[0].name).toEqual('title');
892 expect(mel.children[0].children[1].tagName).toEqual('DD');
893 expect(mel.children[0].children[1].getAttribute('data-type')).toEqual('type:text')
hebasta999d6c12018-04-23 12:44:59 +0200894
Akronfa32c9d2018-11-20 15:39:18 +0100895 expect(mel.children[0].children[0].firstChild.nodeValue).toEqual('author');
896 expect(mel.children[0].children[1].firstChild.nodeValue).toEqual('Sprachpfleger, u.a.');
897 expect(mel.children[0].children[0].attributes[0].value).toEqual('author');
hebasta999d6c12018-04-23 12:44:59 +0200898 });
899
900
Akronfa32c9d2018-11-20 15:39:18 +0100901 /* The keywords in the meta information list should be formatted to be able
902 to chose each keyword separately in the corpusByMatch assistant. */
903 it('keywords should be formatted', function(){
hebasta999d6c12018-04-23 12:44:59 +0200904
Akronfa32c9d2018-11-20 15:39:18 +0100905 //type:string or type:keyword should b not relevant
906 expect(mel.children[1].children[1].getAttribute('data-type')).toEqual('type:string')
907 expect(mel.children[1].children[1].classList.contains('metakeyvalues')).toBeTruthy;
908 expect(mel.children[1].children[1].children[0].tagName).toEqual('DIV');
909 expect(mel.children[1].children[1].children[0].firstChild.nodeValue).toEqual('corenlp');
910 expect(mel.children[1].children[1].children[1].tagName).toEqual('DIV');
911 expect(mel.children[1].children[1].children[1].firstChild.nodeValue).toEqual('corenlp\/constituency');
912
913 expect(mel.children[2].children[1].classList.contains('metakeyvalues')).toBeTruthy;
914 expect(mel.children[2].children[1].children[0].tagName).toEqual('DIV');
915 expect(mel.children[2].children[1].children[0].firstChild.nodeValue).toEqual('kultur');
916 expect(mel.children[2].children[1].children[1].tagName).toEqual('DIV');
917 expect(mel.children[2].children[1].children[1].firstChild.nodeValue).toEqual('film');
hebasta999d6c12018-04-23 12:44:59 +0200918 });
Akrona0ea3c32018-12-14 18:33:48 +0100919
920 it('attachements should be formatted', function(){
Akron0f700762022-01-11 17:21:16 +0100921 //type:attachement with a link (legacy)
Akrona0ea3c32018-12-14 18:33:48 +0100922 expect(mel.children[3].children[1].getAttribute('data-type')).toEqual('type:attachement')
Akron0f700762022-01-11 17:21:16 +0100923 expect(mel.children[3].children[1].classList.contains('metakeyvalues')).toBeFalsy;
924 expect(mel.children[3].children[0].firstChild.nodeValue).toEqual('xlink');
925 expect(mel.children[3].children[1].firstChild.textContent).toEqual('Cool');
926 expect(mel.children[3].children[1].firstChild.tagName).toEqual('A');
Akrona0ea3c32018-12-14 18:33:48 +0100927 expect(mel.children[3].children[1].firstChild.getAttribute('href')).toEqual('https://de.wikipedia.org/wiki/Beispiel');
Akrond3bb85b2019-02-08 10:15:13 +0100928
Akron0f700762022-01-11 17:21:16 +0100929 //type:attachement with a link (uri encoded)
Akrond3bb85b2019-02-08 10:15:13 +0100930 expect(mel.children[4].children[1].getAttribute('data-type')).toEqual('type:attachement')
Akron0f700762022-01-11 17:21:16 +0100931 expect(mel.children[4].children[1].classList.contains('metakeyvalues')).toBeFalsy;
932 expect(mel.children[4].children[0].firstChild.nodeValue).toEqual('xlink2');
933 expect(mel.children[4].children[1].firstChild.textContent).toEqual('Hallo!');
934 expect(mel.children[4].children[1].firstChild.tagName).toEqual('A');
935 expect(mel.children[4].children[1].firstChild.getAttribute('href')).toEqual('https://www.test.de');
Akrond7d3ceb2022-02-07 20:13:09 +0100936
Akron0f700762022-01-11 17:21:16 +0100937 //type:attachement with plain text
938 expect(mel.children[5].children[1].getAttribute('data-type')).toEqual('type:attachement')
939 expect(mel.children[5].children[1].classList.contains('metakeyvalues')).toBeFalsy;
Akrond7d3ceb2022-02-07 20:13:09 +0100940 expect(mel.children[5].children[0].firstChild.nodeValue).toEqual('xlink3');
941 expect(mel.children[5].children[1].firstChild.nodeValue).toEqual('[INVALID URI]');
942
943 //type:attachement with plain text
944 expect(mel.children[6].children[1].getAttribute('data-type')).toEqual('type:attachement')
945 expect(mel.children[6].children[1].classList.contains('metakeyvalues')).toBeFalsy;
946 expect(mel.children[6].children[0].firstChild.nodeValue).toEqual('z-reference');
947 expect(mel.children[6].children[1].firstChild.nodeValue).toEqual('This is a reference');
Akrond3bb85b2019-02-08 10:15:13 +0100948 });
Akrona0ea3c32018-12-14 18:33:48 +0100949
950
hebasta999d6c12018-04-23 12:44:59 +0200951
Akronfa32c9d2018-11-20 15:39:18 +0100952 // Meta information should be sorted alphabetically
953 it('should be alphabetically sorted', function(){
954 var a = mel.children[0].children[0].firstChild.nodeValue;
955 var b = mel.children[1].children[0].firstChild.nodeValue;
956 var c = mel.children[2].children[0].firstChild.nodeValue;
957 expect(a.localeCompare(b)).toBe(-1);
958 expect(b.localeCompare(c)).toBe(-1);
Akrona0ea3c32018-12-14 18:33:48 +0100959 });
960
961
962 it('should handle attachements', function () {
963 let uri = attachementClass.create("data:text/plain;title=new,Hallo");
964 expect(uri.contentType).toEqual("text/plain");
965
966 expect(uri.payload).toEqual("Hallo");
967 expect(uri.base64).toBeFalsy();
968 expect(uri.isLink).toBeFalsy();
969 expect(uri.param["title"]).toEqual("new");
970
971 uri = attachementClass.create("data:application/x.korap-link,https://de.wikipedia.org/wiki/Beispiel");
972 expect(uri.contentType).toEqual("application/x.korap-link");
973 expect(uri.payload).toEqual("https://de.wikipedia.org/wiki/Beispiel");
974 expect(uri.base64).toBeFalsy();
975 expect(uri.isLink).toBeTruthy();
976 expect(uri.inline().textContent).toEqual("https://de.wikipedia.org/wiki/Beispiel");
977 expect(uri.inline().nodeType).toEqual(1);
978 expect(uri.inline().tagName).toEqual("A");
979 expect(uri.inline().getAttribute("rel")).toEqual("noopener noreferrer");
980
981
982 uri = attachementClass.create("data:application/x.korap-link;title=Das ist ein Titel,https://de.wikipedia.org/wiki/Beispiel");
983 expect(uri.contentType).toEqual("application/x.korap-link");
984 expect(uri.payload).toEqual("https://de.wikipedia.org/wiki/Beispiel");
985 expect(uri.base64).toBeFalsy();
986 expect(uri.isLink).toBeTruthy();
987 expect(uri.inline().textContent).toEqual("Das ist ein Titel");
988 expect(uri.inline().nodeType).toEqual(1);
989 expect(uri.inline().tagName).toEqual("A");
990 expect(uri.inline().getAttribute("rel")).toEqual("noopener noreferrer");
991
992
993 uri = attachementClass.create("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D");
994 expect(uri.contentType).toEqual("text/plain");
995 expect(uri.payload).toEqual("Hello, World!");
996 expect(uri.base64).toBeTruthy();
997 expect(uri.isLink).toBeFalsy();
998 expect(uri.inline().nodeType).toEqual(3);
999 expect(uri.inline().textContent).toEqual("Hello, World!");
1000
1001 uri = attachementClass.create("data:text/plain;title= new ; subTitle = old ;base64,SGVsbG8sIFdvcmxkIQ%3D%3D");
1002 expect(uri.contentType).toEqual("text/plain");
1003 expect(uri.payload).toEqual("Hello, World!");
1004 expect(uri.param["title"]).toEqual("new");
1005 expect(uri.param["subTitle"]).toEqual("old");
1006 expect(uri.base64).toBeTruthy();
1007 expect(uri.isLink).toBeFalsy();
1008 expect(uri.inline().nodeType).toEqual(3);
1009 expect(uri.inline().textContent).toEqual("Hello, World!");
1010 });
hebasta999d6c12018-04-23 12:44:59 +02001011 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001012 // table = view.toTable();
1013 // table.sortBy('');
1014 // table.element();
1015 // tree = view.toTree();
1016 // tree.element();
Nils Diewalda297f062015-04-02 00:23:46 +00001017});