blob: 2a1b6b0ebfbce71aa2e7512fc7a742fd74ebaa98 [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",
95 "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",
Akrond3bb85b2019-02-08 10:15:13 +010099 "key": "z-reference",
100 "type": "type:attachement",
101 "value": "data:,This is a reference"
102 }
Akrond8692de2018-07-26 13:06:01 +0200103 ];
104
105
Akron5dc31172019-05-15 18:43:48 +0200106 var snippet = "<span class=\"context-left\"><\/span>"+
107 "<span class=\"match\">" +
Akron1a780fe2019-05-21 15:59:00 +0200108 "<span class=\"cutted\"><\/span>" +
109 "Außerdem " +
Akron5dc31172019-05-15 18:43:48 +0200110 "<span title=\"cnx/l:meist\">" +
Akrond8692de2018-07-26 13:06:01 +0200111 " <span title=\"cnx/p:ADV\">" +
112 " <span title=\"cnx/syn:@PREMOD\">" +
113 " <span title=\"mate/l:meist\">" +
114 " <span title=\"mate/l:meist\">" +
115 " <span title=\"mate/p:ADV\">" +
116 " <span title=\"opennlp/p:ADV\">meist</span>" +
117 " </span>" +
118 " </span>" +
119 " </span>" +
120 " </span>" +
121 " </span>" +
122 "</span>" +
Akronad1e46a2018-09-19 15:55:40 +0200123 "<mark>" +
Akrond8692de2018-07-26 13:06:01 +0200124 "<span title=\"cnx/l:deutlich\">" +
125 " <span title=\"cnx/p:A\">" +
126 " <span title=\"cnx/syn:@PREMOD\">" +
127 " <span title=\"mate/l:deutlich\">" +
128 " <span title=\"mate/m:degree:pos\">" +
129 " <span title=\"mate/p:ADJD\">" +
130 " <span title=\"opennlp/p:ADJD\">deutlich</span>" +
131 " </span>" +
132 " </span>" +
133 " </span>" +
134 " </span>" +
135 " </span>" +
136 "</span>" +
Akronad1e46a2018-09-19 15:55:40 +0200137 "</mark>" +
Akron158fce12019-12-17 14:43:29 +0100138 "<span title=\"dgd/para:incident\">▮</span>" +
Akrond8692de2018-07-26 13:06:01 +0200139 "<span title=\"cnx/l:fähig\">" +
140 " <span title=\"cnx/l:leistung\">" +
141 " <span title=\"cnx/p:A\">" +
142 " <span title=\"cnx/p:ADJA\">" +
143 " <span title=\"cnx/syn:@NH\">" +
144 " <span title=\"mate/l:leistungsfähig\">" +
145 " <span title=\"mate/m:degree:comp\">" +
146 " <span title=\"mate/p:ADJD\">" +
147 " <span title=\"opennlp/p:ADJD\">leistungsfähiger</span>" +
148 " </span>" +
149 " </span>" +
150 " </span>" +
151 " </span>" +
152 " </span>" +
153 " </span>" +
154 " </span>" +
Akron5dc31172019-05-15 18:43:48 +0200155 "</span>" +
156 " und robust sind auch die anderen Traktoren, die hier der Übersicht wegen keine Erwähnung finden können." +
157 "<span class=\"cutted\"><\/span>" +
Akrond8692de2018-07-26 13:06:01 +0200158 "</span>";
159
160 var treeSnippet =
161 "<span class=\"context-left\"></span>" +
162 "<span class=\"match\">" +
163 " <span title=\"xip/c:MC\">" +
164 " <span title=\"xip/c:TOP\">" +
165 " <span title=\"xip/c:PP\">" +
166 " <span title=\"xip/c:PREP\">Mit</span>" +
167 " <span title=\"xip/c:NP\">" +
168 " <span title=\"xip/c:DET\">dieser</span>" +
169 " <span title=\"xip/c:NPA\">" +
170 " <span title=\"xip/c:NOUN\">Methode</span>" +
171 " </span>" +
172 " </span>" +
173 " </span>" +
174 " <span title=\"xip/c:VERB\">ist</span>" +
175 " <mark>" +
176 " <span title=\"xip/c:NP\">" +
177 " <span title=\"xip/c:PRON\">es</span>" +
178 " </span>" +
179 " <span title=\"xip/c:AP\">" +
180 " <span title=\"xip/c:ADV\">nun</span>" +
181 " <span title=\"xip/c:ADJ\">möglich</span>" +
182 " </span>" +
183 " </mark>" +
184 " <span title=\"xip/c:ADV\">z. B.</span>" +
185 " <span title=\"xip/c:NPA\">" +
186 " <span title=\"xip/c:NP\">" +
187 " <span title=\"xip/c:NOUN\">Voice</span>" +
188 " </span>" +
189 " </span>" + "(" +
190 " <span title=\"xip/c:INS\">" +
191 " <span title=\"xip/c:NPA\">" +
192 " <span title=\"xip/c:NP\">" +
193 " <span title=\"xip/c:NOUN\">Sprache</span>" +
194 " </span>" +
195 " </span>" +
196 " </span>" + ")" +
197 " <span title=\"xip/c:VERB\">bevorzugt</span>" +
198 " <span title=\"xip/c:PP\">" +
199 " <span title=\"xip/c:PREP\">in</span>" +
200 " <span title=\"xip/c:NP\">" +
201 " <span title=\"xip/c:PRON\">der</span>" +
202 " </span>" +
203 " <span title=\"xip/c:NPA\">" +
204 " <span title=\"xip/c:NP\">" +
205 " <span title=\"xip/c:NOUN\">Bridge</span>" +
206 " </span>" +
207 " </span>" +
208 " </span>" +
209 " <span title=\"xip/c:INFC\">" +
210 " <span title=\"xip/c:INS\">" +
211 " <span title=\"xip/c:VERB\">weiterzugeben</span>" +
212 " </span>" +
213 " </span>" +
214 " </span>" +
215 " </span>" +
216 "</span>" +
217 "<span class=\"context-right\"></span>";
218
Akron3bdac532019-03-04 13:24:43 +0100219 var treeSnippetHierarchy =
220 "<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 +0200221
Akron158fce12019-12-17 14:43:29 +0100222 function matchElementFactory () {
Akrond8692de2018-07-26 13:06:01 +0200223 var me = document.createElement('li');
224
225 me.setAttribute(
226 'data-available-info',
227 'base/s=spans corenlp/c=spans corenlp/ne=tokens corenlp/p=tokens' +
228 ' corenlp/s=spans glemm/l=tokens mate/l=tokens mate/m=tokens' +
229 ' mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens' +
230 ' tt/p=tokens tt/s=spans');
231
232 me.setAttribute('data-corpus-id', 'WPD');
233 me.setAttribute('data-doc-id', 'FFF');
234 me.setAttribute('data-text-id', '01460');
235 me.setAttribute('data-text-sigle', 'WPD/FFF/01460');
236 me.setAttribute('data-match-id', 'p119-120');
237 me.innerHTML = '<div><div class="snippet">check</div></div><p class="ref">me</p>';
238 return me;
239 };
240
241 function matchElementReal () {
242 var me = document.createElement('em');
243 me.innerHTML =
244 '<li data-match-id="p85183-85184"' +
245 ' data-text-sigle="GOE/AGI/00000"' +
246 ' 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"' +
247 ' 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;}"' +
248 ' id="GOE/AGI/00000#p85183-85184">' +
249 '<div>' +
250 '<div class="flag"></div>' +
251 '<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>' +
252 '</div>' +
253 '<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>' +
254 '</li>';
255 return me.firstChild;
256 };
257
258 var beforeAllFunc = function () {
259 // Override getMatchInfo API call
260 KorAP.API.getMatchInfo = function (x, param, cb) {
261 if (param['spans'] === undefined || param['spans'] === false)
262 cb({ "snippet": snippet });
263 else
264 cb({ "snippet": treeSnippet });
265 };
266 };
267
268 var afterAllFunc = function () {
269 KorAP.API.getMatchInfo = undefined;
hebasta87f1b1f2019-07-30 13:03:23 +0200270 KorAP.TreeMenu = undefined;
Akrond8692de2018-07-26 13:06:01 +0200271 var body = document.body;
hebasta87f1b1f2019-07-30 13:03:23 +0200272 var i = body.children.length - 1;
273 while (i >= 0) {
Akrond8692de2018-07-26 13:06:01 +0200274 if (body.children[i].nodeType && body.children[i].nodeType === 1) {
275 if (!body.children[i].classList.contains("jasmine_html-reporter")) {
276 body.removeChild(body.children[i]);
277 };
278 };
hebasta87f1b1f2019-07-30 13:03:23 +0200279 i--;
Akrond8692de2018-07-26 13:06:01 +0200280 };
281 };
Akron671fdb92017-09-12 18:09:46 +0200282
Nils Diewald7c8ced22015-04-15 19:21:00 +0000283 describe('KorAP.InfoLayer', function () {
Akrond8692de2018-07-26 13:06:01 +0200284 beforeAll(beforeAllFunc);
285 afterAll(afterAllFunc);
Nils Diewalda297f062015-04-02 00:23:46 +0000286
Nils Diewald7c8ced22015-04-15 19:21:00 +0000287 it('should be initializable', function () {
288 expect(
Akron671fdb92017-09-12 18:09:46 +0200289 function() { infoClass.create() }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000290 ).toThrow(new Error("Missing parameters"));
Nils Diewalda297f062015-04-02 00:23:46 +0000291
Nils Diewald7c8ced22015-04-15 19:21:00 +0000292 expect(
Akron671fdb92017-09-12 18:09:46 +0200293 function() { infoClass.create("base") }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000294 ).toThrow(new Error("Missing parameters"));
Nils Diewalda297f062015-04-02 00:23:46 +0000295
Nils Diewald7c8ced22015-04-15 19:21:00 +0000296 var layer = infoClass.create("base", "s");
297 expect(layer).toBeTruthy();
298 expect(layer.foundry).toEqual("base");
299 expect(layer.layer).toEqual("s");
300 expect(layer.type).toEqual("tokens");
Nils Diewalda297f062015-04-02 00:23:46 +0000301
Nils Diewald7c8ced22015-04-15 19:21:00 +0000302 layer = infoClass.create("cnx", "syn", "spans");
303 expect(layer).toBeTruthy();
304 expect(layer.foundry).toEqual("cnx");
305 expect(layer.layer).toEqual("syn");
306 expect(layer.type).toEqual("spans");
Nils Diewald58141332015-04-07 16:18:45 +0000307 });
308 });
Nils Diewalda297f062015-04-02 00:23:46 +0000309
Nils Diewalda297f062015-04-02 00:23:46 +0000310
Nils Diewald7c8ced22015-04-15 19:21:00 +0000311 describe('KorAP.Match', function () {
Akrond8692de2018-07-26 13:06:01 +0200312 beforeAll(beforeAllFunc);
313 afterAll(afterAllFunc);
314
Nils Diewald7c8ced22015-04-15 19:21:00 +0000315 var match = {
316 'corpusID' : 'WPD',
317 'docID' : 'UUU',
318 'textID' : '01912',
319 'matchID' : 'p121-122',
Akron0a6768f2016-07-13 18:00:43 +0200320 'textSigle' : 'WPD/UUU/01912',
Nils Diewald7c8ced22015-04-15 19:21:00 +0000321 'available' : available
322 };
323
Nils Diewald7c8ced22015-04-15 19:21:00 +0000324 it('should be initializable by Object', function () {
325 expect(function() {
Akron671fdb92017-09-12 18:09:46 +0200326 matchClass.create()
Nils Diewald7c8ced22015-04-15 19:21:00 +0000327 }).toThrow(new Error('Missing parameters'));
328
329 expect(matchClass.create(match)).toBeTruthy();
330
331 var m = matchClass.create(match);
Akron0a6768f2016-07-13 18:00:43 +0200332 expect(m.textSigle).toEqual("WPD/UUU/01912");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000333 expect(m.matchID).toEqual("p121-122");
334
335 // /corpus/WPD/UUU.01912/p121-122/matchInfo?spans=false&foundry=*
336 var m = matchClass.create(match);
337
338 // Spans:
339 var spans = m.getSpans();
340 expect(spans[0].foundry).toEqual("base");
341 expect(spans[0].layer).toEqual("s");
342
343 expect(spans[1].foundry).toEqual("corenlp");
344 expect(spans[1].layer).toEqual("c");
345
346 expect(spans[2].foundry).toEqual("corenlp");
347 expect(spans[2].layer).toEqual("s");
348
349 expect(spans[spans.length-1].foundry).toEqual("tt");
350 expect(spans[spans.length-1].layer).toEqual("s");
351
352 // Tokens:
353 var tokens = m.getTokens();
354 expect(tokens[0].foundry).toEqual("corenlp");
355 expect(tokens[0].layer).toEqual("ne");
356
357 expect(tokens[1].foundry).toEqual("corenlp");
358 expect(tokens[1].layer).toEqual("p");
359
360 expect(tokens[tokens.length-1].foundry).toEqual("tt");
361 expect(tokens[tokens.length-1].layer).toEqual("p");
Nils Diewald58141332015-04-07 16:18:45 +0000362 });
Nils Diewalda297f062015-04-02 00:23:46 +0000363
364
Akroncdb0baa2016-11-07 01:52:11 +0100365 it('should be initializable by Node 1', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000366 var m = matchClass.create(matchElementFactory());
Akron0a6768f2016-07-13 18:00:43 +0200367 expect(m.textSigle).toEqual("WPD/FFF/01460");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000368 expect(m.matchID).toEqual("p119-120");
Nils Diewalda297f062015-04-02 00:23:46 +0000369
Nils Diewald7c8ced22015-04-15 19:21:00 +0000370 // Spans:
371 var spans = m.getSpans();
372 expect(spans[0].foundry).toEqual("base");
373 expect(spans[0].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000374
Nils Diewald7c8ced22015-04-15 19:21:00 +0000375 expect(spans[1].foundry).toEqual("corenlp");
376 expect(spans[1].layer).toEqual("c");
Nils Diewalda297f062015-04-02 00:23:46 +0000377
Nils Diewald7c8ced22015-04-15 19:21:00 +0000378 expect(spans[2].foundry).toEqual("corenlp");
379 expect(spans[2].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000380
Nils Diewald7c8ced22015-04-15 19:21:00 +0000381 expect(spans[spans.length-1].foundry).toEqual("tt");
382 expect(spans[spans.length-1].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000383
Nils Diewald7c8ced22015-04-15 19:21:00 +0000384 // Tokens:
385 var tokens = m.getTokens();
386 expect(tokens[0].foundry).toEqual("corenlp");
387 expect(tokens[0].layer).toEqual("ne");
Nils Diewalda297f062015-04-02 00:23:46 +0000388
Nils Diewald7c8ced22015-04-15 19:21:00 +0000389 expect(tokens[1].foundry).toEqual("corenlp");
390 expect(tokens[1].layer).toEqual("p");
Nils Diewalda297f062015-04-02 00:23:46 +0000391
Nils Diewald7c8ced22015-04-15 19:21:00 +0000392 expect(tokens[tokens.length-1].foundry).toEqual("tt");
393 expect(tokens[tokens.length-1].layer).toEqual("p");
Nils Diewalda297f062015-04-02 00:23:46 +0000394
Nils Diewald7c8ced22015-04-15 19:21:00 +0000395 });
Nils Diewalda297f062015-04-02 00:23:46 +0000396
Akroncdb0baa2016-11-07 01:52:11 +0100397 it('should be initializable by Node 2', function () {
398 var ele = matchElementReal();
399 var m = matchClass.create(ele);
400 expect(m.textSigle).toEqual("GOE/AGI/00000");
401 expect(m.matchID).toEqual("p85183-85184");
402 });
403
Akron3c390c42020-03-30 09:06:21 +0200404 it('should be initializable when active', function () {
405 var e = matchElementFactory();
406 e.setAttribute('class', 'active');
407
408 expect(e.classList.contains('active')).toBe(true);
409 expect(e["_match"]).toBe(undefined);
410
411 var m = matchClass.create(e);
412
413 expect(e["_match"]).not.toBe(undefined);
414
415 // Open the match
416 m.init();
417
418 expect(e["_match"]).not.toBe(undefined);
419
420 actions = e.querySelector("p.ref > div.action.button-group").children;
421
422 expect(actions[0].getAttribute("class")).toEqual("metatable");
423 expect(actions[1].getAttribute("class")).toEqual("info");
424 expect(actions[2].getAttribute("class")).toEqual("tree");
425
426 // Close the match
427 expect(e.querySelector("div.action.button-group > span.minimize")).toBe(null);
428 });
Akroncdb0baa2016-11-07 01:52:11 +0100429
Nils Diewald7c8ced22015-04-15 19:21:00 +0000430 it('should react to gui actions', function () {
431 var e = matchElementFactory();
Nils Diewalda297f062015-04-02 00:23:46 +0000432
Nils Diewald7c8ced22015-04-15 19:21:00 +0000433 expect(e.classList.contains('active')).toBe(false);
434 expect(e["_match"]).toBe(undefined);
Nils Diewalda297f062015-04-02 00:23:46 +0000435
Nils Diewald7c8ced22015-04-15 19:21:00 +0000436 var m = matchClass.create(e);
437
438 expect(e.classList.contains('active')).toBe(false);
439 expect(e["_match"]).not.toBe(undefined);
hebasta87f1b1f2019-07-30 13:03:23 +0200440
Nils Diewald7c8ced22015-04-15 19:21:00 +0000441 // Open the match
442 m.open();
hebasta87f1b1f2019-07-30 13:03:23 +0200443
Nils Diewald7c8ced22015-04-15 19:21:00 +0000444 expect(e.classList.contains('active')).toBe(true);
445 expect(e["_match"]).not.toBe(undefined);
446
Akronbfe912c2018-07-17 19:30:52 +0200447 actions = e.querySelector("p.ref > div.action.button-group").children;
Akrond141a362018-07-10 18:12:13 +0200448
Akronbfe912c2018-07-17 19:30:52 +0200449 expect(actions[0].getAttribute("class")).toEqual("metatable");
Akronc296ca22018-04-24 16:35:26 +0200450 expect(actions[1].getAttribute("class")).toEqual("info");
451 expect(actions[2].getAttribute("class")).toEqual("tree");
Akron3c390c42020-03-30 09:06:21 +0200452
453 expect(e.querySelector("div.action.button-group > span.minimize")).not.toBe(null);
Akronc296ca22018-04-24 16:35:26 +0200454
Nils Diewald7c8ced22015-04-15 19:21:00 +0000455 // Close the match
Akronec6bb8e2018-08-29 13:07:56 +0200456 m.minimize();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000457 expect(e.classList.contains('active')).toBe(false);
458 expect(e["_match"]).not.toBe(undefined);
Nils Diewald58141332015-04-07 16:18:45 +0000459 });
Akrone57e8802020-10-17 08:23:45 +0200460
461 it('should toggle', function () {
462 var e = matchElementFactory();
463
464 expect(e.classList.contains('active')).toBe(false);
465 expect(e["_match"]).toBe(undefined);
466
467 var m = matchClass.create(e);
468
469 expect(e.classList.contains('active')).toBe(false);
470 expect(e["_match"]).not.toBe(undefined);
471
472 // Open the match
473 m.open();
474
475 expect(e.classList.contains('active')).toBe(true);
476 expect(e["_match"]).not.toBe(undefined);
477
478 m.toggle();
479
480 expect(e.classList.contains('active')).toBe(false);
481 expect(e["_match"]).not.toBe(undefined);
482
483 m.toggle();
484
485 expect(e.classList.contains('active')).toBe(true);
486 expect(e["_match"]).not.toBe(undefined);
487 });
488
Akrond8692de2018-07-26 13:06:01 +0200489 it('should open tree menu', function () {
Akronc296ca22018-04-24 16:35:26 +0200490 var e = matchElementFactory();
491 var m = matchClass.create(e);
492 m.open();
Akronbfe912c2018-07-17 19:30:52 +0200493 var relation = e.querySelector("p.ref > div.action.button-group > span:nth-of-type(3)");
Akronc296ca22018-04-24 16:35:26 +0200494 expect(relation.getAttribute("class")).toEqual("tree");
Akron52ed22d2018-07-11 17:05:19 +0200495 expect(document.getElementsByClassName("button-group-list").length).toEqual(0);
Akronc296ca22018-04-24 16:35:26 +0200496 expect(document.activeElement.tagName).toEqual("BODY");
hebasta87f1b1f2019-07-30 13:03:23 +0200497
Akronc296ca22018-04-24 16:35:26 +0200498 // Show menu
499 relation.click();
Akron52ed22d2018-07-11 17:05:19 +0200500 expect(document.getElementsByClassName("button-group-list").length).toEqual(1);
Akronc296ca22018-04-24 16:35:26 +0200501 expect(document.activeElement.tagName).toEqual("UL");
hebasta87f1b1f2019-07-30 13:03:23 +0200502
Akronc296ca22018-04-24 16:35:26 +0200503 // Choose first tree
Akron52ed22d2018-07-11 17:05:19 +0200504 document.getElementsByClassName("button-group-list")[0].getElementsByTagName("li")[1].click();
Akronc296ca22018-04-24 16:35:26 +0200505 expect(e.querySelector("div.matchinfo div.matchtree h6 span").innerText).toEqual("corenlp");
506
507 // This should blur the focus
508 expect(document.activeElement.tagName).toEqual("BODY");
hebasta87f1b1f2019-07-30 13:03:23 +0200509
Akronc296ca22018-04-24 16:35:26 +0200510 });
511
512 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000513
Akron7f9a6a32018-07-18 15:05:23 +0200514 describe('KorAP.TableView', function () {
Akrond8692de2018-07-26 13:06:01 +0200515 beforeAll(beforeAllFunc);
516 afterAll(afterAllFunc);
Akron5dc31172019-05-15 18:43:48 +0200517
518 let longString = " und robust sind auch die anderen Traktoren, die hier der Übersicht wegen keine Erwähnung finden können.";
519
Akron7f9a6a32018-07-18 15:05:23 +0200520 var table;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000521
Akron7f9a6a32018-07-18 15:05:23 +0200522 var matchObj = matchClass.create(match);
523 var tableObj = tableClass.create(matchObj);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000524
525 var table1, table2;
526
Nils Diewald7c8ced22015-04-15 19:21:00 +0000527 it('should fail to load a table async', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200528 expect(tableObj).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000529
Akron7f9a6a32018-07-18 15:05:23 +0200530 tableObj.getData([], function (tablen) {
Akron671fdb92017-09-12 18:09:46 +0200531 table1 = tablen;
532 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000533 });
534 });
535
Akron671fdb92017-09-12 18:09:46 +0200536
Akronaeeb8252018-09-19 18:51:00 +0200537 xit('should\'nt be parsable (async)', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000538 expect(table1).not.toBeTruthy();
539 });
540
Nils Diewald7c8ced22015-04-15 19:21:00 +0000541
Nils Diewald7c8ced22015-04-15 19:21:00 +0000542 it('should be retrieved async', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200543 expect(tableObj).toBeTruthy();
544 tableObj.getData(undefined, function (x) {
Akron671fdb92017-09-12 18:09:46 +0200545 table = x;
546 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000547 });
548 });
Nils Diewalda297f062015-04-02 00:23:46 +0000549
Akron7f9a6a32018-07-18 15:05:23 +0200550 it('should parse into a table (async)', function () {
551 expect(table).toBeTruthy();
Akron5b1a6af2018-02-05 15:41:16 +0100552
Akron158fce12019-12-17 14:43:29 +0100553 expect(table.length()).toBe(8);
Akron7f9a6a32018-07-18 15:05:23 +0200554
Akron1a780fe2019-05-21 15:59:00 +0200555 expect(table.getToken(0)).toBe("");
556 expect(table.getToken(1)).toBe("Außerdem ");
557 expect(table.getToken(2)).toBe("meist");
558 expect(table.getToken(3)).toBe("deutlich");
Akron158fce12019-12-17 14:43:29 +0100559 expect(table.getToken(5)).toBe("leistungsfähiger");
560 expect(table.getToken(6)).toBe(longString);
Akron7f9a6a32018-07-18 15:05:23 +0200561
Akron1a780fe2019-05-21 15:59:00 +0200562 expect(table.getValue(2, "cnx", "p")[0]).toBe("ADV");
563 expect(table.getValue(2, "cnx", "syn")[0]).toBe("@PREMOD");
564 expect(table.getValue(2, "mate", "l")[0]).toBe("meist");
565 expect(table.getValue(2, "mate", "l")[1]).toBeUndefined();
Akron7f9a6a32018-07-18 15:05:23 +0200566
Akron158fce12019-12-17 14:43:29 +0100567 expect(table.getValue(5, "cnx", "l")[0]).toBe("fähig");
568 expect(table.getValue(5, "cnx", "l")[1]).toBe("leistung");
Akron7f9a6a32018-07-18 15:05:23 +0200569 });
570
571 it('should be rendered async', function () {
Akron5b1a6af2018-02-05 15:41:16 +0100572 var e = table.element().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000573 expect(e.nodeName).toBe('TABLE');
574 expect(e.children[0].nodeName).toBe('THEAD');
575 var tr = e.children[0].children[0];
576 expect(tr.nodeName).toBe('TR');
577 expect(tr.children[0].nodeName).toBe('TH');
Nils Diewald58141332015-04-07 16:18:45 +0000578
Nils Diewald7c8ced22015-04-15 19:21:00 +0000579 expect(tr.children[0].firstChild.nodeValue).toBe('Foundry');
580 expect(tr.children[1].firstChild.nodeValue).toBe('Layer');
Akron1a780fe2019-05-21 15:59:00 +0200581
582 expect(tr.children[2].classList.contains('cutted')).toBeTruthy();
583 expect(tr.children[3].firstChild.nodeValue).toBe('Außerdem ');
584
585
586 expect(tr.children[4].firstChild.nodeValue).toBe('meist');
Akronad1e46a2018-09-19 15:55:40 +0200587 expect(tr.children[4].classList.contains('mark')).toBeFalsy();
Akron1a780fe2019-05-21 15:59:00 +0200588 expect(tr.children[5].firstChild.nodeValue).toBe('deutlich');
589 expect(tr.children[5].classList.contains('mark')).toBeTruthy();
Akron158fce12019-12-17 14:43:29 +0100590 expect(tr.children[6].firstChild.nodeValue).toBe('▮');
591 expect(tr.children[7].firstChild.nodeValue).toBe('leistungsfähiger');
592 expect(tr.children[7].classList.contains('mark')).toBeFalsy();
593 expect(tr.children[7].hasAttribute("title")).toBeFalsy();
594 expect(tr.children[8].firstChild.nodeValue).toBe(longString);
595 expect(tr.children[8].getAttribute("title")).toBe(longString);
596 expect(tr.children[9].classList.contains('cutted')).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000597
598 // first row
599 tr = e.children[1].children[0];
600 expect(tr.nodeName).toBe('TR');
601 expect(tr.getAttribute('tabindex')).toEqual('0');
602 expect(tr.children[0].nodeName).toBe('TH');
603 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
604 expect(tr.children[1].firstChild.nodeValue).toEqual('l');
Akron1a780fe2019-05-21 15:59:00 +0200605 expect(tr.children[4].firstChild.nodeValue).toEqual('meist');
606 expect(tr.children[5].firstChild.nodeValue).toEqual('deutlich');
Akron158fce12019-12-17 14:43:29 +0100607 expect(tr.children[6].firstChild).toBeNull();
608 expect(tr.children[7].firstChild.firstChild.nodeValue).toEqual('fähig');
609 expect(tr.children[7].lastChild.firstChild.nodeValue).toEqual('leistung');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000610
611 // second row
612 tr = e.children[1].children[1];
613 expect(tr.nodeName).toBe('TR');
614 expect(tr.getAttribute('tabindex')).toEqual('0');
615 expect(tr.children[0].nodeName).toBe('TH');
616 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
617 expect(tr.children[1].firstChild.nodeValue).toEqual('p');
Akron1a780fe2019-05-21 15:59:00 +0200618 expect(tr.children[4].firstChild.nodeValue).toEqual('ADV');
619 expect(tr.children[5].firstChild.nodeValue).toEqual('A');
Akron158fce12019-12-17 14:43:29 +0100620 expect(tr.children[6].firstChild).toBeNull();
621 expect(tr.children[7].firstChild.firstChild.nodeValue).toEqual('A');
622 expect(tr.children[7].lastChild.firstChild.nodeValue).toEqual('ADJA');
Akronf2279c42017-12-21 13:48:46 +0100623
Akron158fce12019-12-17 14:43:29 +0100624 expect(tr.children[7].firstChild.getAttribute("title")).toEqual('Adjective');
Akron1a780fe2019-05-21 15:59:00 +0200625 expect(tr.children[4].getAttribute("title")).toEqual('Adverb');
Nils Diewald58141332015-04-07 16:18:45 +0000626 });
Akron7f9a6a32018-07-18 15:05:23 +0200627
628
629 it('should parse into a table view (sync)', function () {
630 var matchElement = matchElementFactory();
631 expect(matchElement.tagName).toEqual('LI');
632
633 // Match
634 expect(matchElement.children[0].tagName).toEqual('DIV');
635
636 // snippet
637 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
638 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
639 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
640
641 // reference
642 expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
643 expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
644
645 // not yet
646 expect(matchElement.children[0].children[1]).toBe(undefined);
647
648 /*
649 var info = matchClass.create(matchElement).info();
650 info.showTable();
651 */
652 var matchObj = matchClass.create(matchElement);
653 matchObj.open();
654
655 // Match
656 expect(matchElement.children[0].tagName).toEqual('DIV');
657
658 // snippet
659 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
660
661 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
662
663 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
664
665 // reference
666
667 expect(matchElement.children[2].classList.contains('ref')).toBeTruthy();
668 expect(matchElement.children[2].childNodes[1].nodeValue).toEqual('me');
669
670 // Add table
671 matchObj.panel.addTable();
672
673 // now
674 var infotable = matchElement.children[1];
675 expect(infotable.tagName).toEqual('DIV');
676
677 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
678
679 expect(infotable.firstChild.firstChild.firstChild.classList.contains('matchtable')).toBeTruthy();
680
681 // expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
682 });
683
Akron158fce12019-12-17 14:43:29 +0100684 it('should parse into a table view with non-verbal elements (sync)', function () {
685 var matchElement = matchElementFactory();
686 expect(matchElement.tagName).toEqual('LI');
687 });
688
Nils Diewald58141332015-04-07 16:18:45 +0000689 });
Nils Diewalda297f062015-04-02 00:23:46 +0000690
Akron7f9a6a32018-07-18 15:05:23 +0200691 describe('KorAP.RelationsView', function () {
Akrond8692de2018-07-26 13:06:01 +0200692 beforeAll(beforeAllFunc);
693 afterAll(afterAllFunc);
694
Nils Diewald7c8ced22015-04-15 19:21:00 +0000695 var tree;
Nils Diewalda297f062015-04-02 00:23:46 +0000696
Nils Diewald7c8ced22015-04-15 19:21:00 +0000697 it('should be rendered async 1', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200698 var matchObj = matchClass.create(match);
699 var relObj = relClass.create(matchObj);
700 expect(relObj).toBeTruthy();
701 relObj.getData(undefined, undefined, "spans", function (y) {
Akron671fdb92017-09-12 18:09:46 +0200702 tree = y;
703 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000704 });
705 });
Nils Diewalda297f062015-04-02 00:23:46 +0000706
Nils Diewald7c8ced22015-04-15 19:21:00 +0000707 it('should be rendered async 2', function () {
Akron7f9a6a32018-07-18 15:05:23 +0200708 expect(tree).toBeTruthy();
709 expect(tree.nodes()).toEqual(49);
710
Nils Diewald7c8ced22015-04-15 19:21:00 +0000711 var e = tree.element();
712 expect(e.nodeName).toEqual('svg');
713 expect(e.getElementsByTagName('g').length).toEqual(48);
Nils Diewald58141332015-04-07 16:18:45 +0000714 });
Akron7f9a6a32018-07-18 15:05:23 +0200715
716
717 it('should add a tree view async 2', function () {
718 var matchElement = matchElementFactory();
719 var matchObj = matchClass.create(matchElement);
720 matchObj.open();
721 matchObj.panel.addTree('mate', 'beebop', 'spans', function () {
722 done();
723 });
724
725 // With added tree
726 var tree = matchElement.children[1].firstChild.firstChild.firstChild;
727 expect(tree.tagName).toEqual('DIV');
728 expect(tree.classList.contains('matchtree')).toBeTruthy();
729 expect(tree.children[0].tagName).toEqual('H6');
730 expect(tree.children[0].children[0].tagName).toEqual('SPAN');
731 expect(tree.children[0].children[0].firstChild.nodeValue).toEqual('mate');
732 expect(tree.children[0].children[1].tagName).toEqual('SPAN');
733 expect(tree.children[0].children[1].firstChild.nodeValue).toEqual('beebop');
734
735 expect(tree.children[1].tagName).toEqual('DIV');
736 });
737
Akron3bdac532019-03-04 13:24:43 +0100738 it('should make the tree downloadable', function () {
739 var treeClass = matchHierClass.create(treeSnippetHierarchy);
740 var treeElement = treeClass.element();
741 expect(treeElement.tagName).toEqual("svg");
742
743 var base64 = treeClass.toBase64();
744 var str = atob(base64);
745 expect(str).toMatch(new RegExp('<defs><style>path'));
746 expect(str).not.toMatch(new RegExp('&nbsp;'));
747 expect(str).toMatch(new RegExp('&amp;'));
748 });
Nils Diewald58141332015-04-07 16:18:45 +0000749 });
Nils Diewalda297f062015-04-02 00:23:46 +0000750
Nils Diewald7c8ced22015-04-15 19:21:00 +0000751
752 describe('KorAP.MatchTreeItem', function () {
Akrond8692de2018-07-26 13:06:01 +0200753 beforeAll(beforeAllFunc);
754 afterAll(afterAllFunc);
755
Nils Diewald7c8ced22015-04-15 19:21:00 +0000756 it('should be initializable', function () {
757 var mi = matchTreeItemClass.create(['cnx/c', 'cnx', 'c'])
758 expect(mi.element().firstChild.nodeValue).toEqual('cnx/c');
759 expect(mi.lcField()).toEqual(' cnx/c');
760 expect(mi.foundry()).toEqual('cnx');
761 expect(mi.layer()).toEqual('c');
762 });
Nils Diewalda297f062015-04-02 00:23:46 +0000763 });
Nils Diewalda297f062015-04-02 00:23:46 +0000764
765
Akron671fdb92017-09-12 18:09:46 +0200766 describe('KorAP.MatchRelation', function () {
Akrond8692de2018-07-26 13:06:01 +0200767 beforeAll(beforeAllFunc);
768 afterAll(afterAllFunc);
Akron671fdb92017-09-12 18:09:46 +0200769
770 var relExample = "<span class=\"context-left\"></span>" +
771 "<span class=\"match\">" +
772 " <span xml:id=\"token-GOE/AGA/01784-p199\">" +
773 " <span xlink:title=\"malt/d:ADV\" " +
774 " xlink:type=\"simple\" " +
775 " xlink:href=\"#token-GOE/AGA/01784-p199\">dann</span>" +
776 " </span>" +
777 " zog " +
778 " <span xlink:title=\"malt/d:SUBJ\" " +
779 " xlink:type=\"simple\" " +
780 " xlink:href=\"#token-GOE/AGA/01784-p199\">ich</span>" +
781 " <span xml:id=\"token-GOE/AGA/01784-p202\">" +
782 " <span xlink:title=\"malt/d:OBJA\" " +
783 " xlink:type=\"simple\" " +
784 " xlink:href=\"#token-GOE/AGA/01784-p199\">mich</span>" +
785 " </span>" +
786 "</span>" +
787 "<span class=\"context-right\"></span>";
788
789
790 it('should be initializable', function () {
Akrond8692de2018-07-26 13:06:01 +0200791 var tree = matchRelClass.create();
Akron671fdb92017-09-12 18:09:46 +0200792 expect(tree.size()).toBe(0);
793 });
794
795 it('should be parse string data', function () {
Akrond8692de2018-07-26 13:06:01 +0200796 var tree = matchRelClass.create(relExample);
Akron671fdb92017-09-12 18:09:46 +0200797 expect(tree.size()).toBe(4);
798 });
Akron0a785d42020-10-12 17:21:46 +0200799
800 it('should accept missing data', function () {
801 var relExample2 = "<span class=\"context-left\"><\/span>"+
802 "<span class=\"match\">"+
803 "{{"+
804 "<span xml:id=\"token-WUD17\/D95\/09441-p180\">"+
805 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p179\">Wikiläum<\/span>"+
806 "<\/span>"+
807 "|"+
808 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p180\">Silber<\/span>"+
809 "|"+
810 "<span xlink:title=\"malt\/d:DET\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p183\">Dein<\/span>"+
811 " "+
812 "<span xml:id=\"token-WUD17\/D95\/09441-p183\">"+
813 "<span xlink:title=\"malt\/d:ROOT\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p179-196\">Freund<\/span>"+
814 "<\/span>"+
815 " "+
816 "<span xlink:title=\"malt\/d:DET\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p185\">der<\/span>"+
817 " "+
818 "<span xml:id=\"token-WUD17\/D95\/09441-p185-186\">"+
819 "<span xml:id=\"token-WUD17\/D95\/09441-p185\">"+
820 "<mark>"+
821 "<span xlink:title=\"malt\/d:GMOD\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p183\">Baum<\/span>"+
822 "<\/mark>"+
823 "<\/span>"+
824 "| "+
825 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p185-186\">09:38<\/span>"+
826 "<\/span>"+
827 ", "+
828 "<span xlink:title=\"malt\/d:ATTR\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p188\">22.<\/span>"+
829 " "+
830 "<span xml:id=\"token-WUD17\/D95\/09441-p188\">"+
831 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p183\">Aug.<\/span>"+
832 "<\/span>"+
833 " "+
834 "<span xml:id=\"token-WUD17\/D95\/09441-p189\">"+
835 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p188\">2015<\/span>"+
836 "<\/span>"+
837 " ("+
838 "<span xlink:title=\"malt\/d:PAR\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p189\">CEST<\/span>"+
839 ")"+
840 "<\/span>"+
841 "<span class=\"context-right\"><\/span>";
842 var tree = matchRelClass.create(relExample2);
843 expect(tree.size()).toBe(18);
844 var treeElement = tree.element();
845 expect(treeElement.tagName).toEqual("svg");
846 tree.show();
847 expect(treeElement.querySelector("text[text-anchor=\"middle\"]").textContent).toEqual("APP");
848 });
Akron671fdb92017-09-12 18:09:46 +0200849 });
850
851
Nils Diewald7c8ced22015-04-15 19:21:00 +0000852 describe('KorAP.MatchTreeMenu', function () {
Akrond8692de2018-07-26 13:06:01 +0200853 beforeAll(beforeAllFunc);
854 afterAll(afterAllFunc);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000855
856 it('should be initializable', function () {
Akrond8692de2018-07-26 13:06:01 +0200857 var menu = matchTreeMenuClass.create([
Akron671fdb92017-09-12 18:09:46 +0200858 ['cnx/c', 'cnx', 'c'],
859 ['xip/c', 'xip', 'c']
Akrond8692de2018-07-26 13:06:01 +0200860 ], matchTreeItemClass);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000861
Akrond8692de2018-07-26 13:06:01 +0200862 expect(menu.itemClass()).toEqual(matchTreeItemClass);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000863 expect(menu.element().nodeName).toEqual('UL');
Akronaba7a5a2016-08-15 21:58:33 +0200864 expect(menu.element().classList.contains('visible')).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000865 expect(menu.limit()).toEqual(6);
866 menu.show();
Akronaba7a5a2016-08-15 21:58:33 +0200867 expect(menu.element().classList.contains('visible')).toBeTruthy();
Akronc1457bf2015-06-11 19:24:00 +0200868 expect(menu.item(0).active()).toBe(false);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000869 });
Nils Diewalda297f062015-04-02 00:23:46 +0000870 });
hebasta999d6c12018-04-23 12:44:59 +0200871
872 //Test display and sorting of meta information
873 describe('KorAP.Meta', function(){
Akrond8692de2018-07-26 13:06:01 +0200874 beforeAll(beforeAllFunc);
875 afterAll(afterAllFunc);
876
877 var met = metaClass.create(match, fields);
hebasta999d6c12018-04-23 12:44:59 +0200878 var mel = met.element();
879
880 // Meta information should be parsed into a list
881 it('should parse in a meta view', function(){
Akronfa32c9d2018-11-20 15:39:18 +0100882 expect(mel.tagName).toEqual('DL');
883 expect(mel.children[0].tagName).toEqual('DIV');
884 expect(mel.children[0].children[0].tagName).toEqual('DT');
885 expect(mel.children[0].children[0].attributes[0].name).toEqual('title');
886 expect(mel.children[0].children[1].tagName).toEqual('DD');
887 expect(mel.children[0].children[1].getAttribute('data-type')).toEqual('type:text')
hebasta999d6c12018-04-23 12:44:59 +0200888
Akronfa32c9d2018-11-20 15:39:18 +0100889 expect(mel.children[0].children[0].firstChild.nodeValue).toEqual('author');
890 expect(mel.children[0].children[1].firstChild.nodeValue).toEqual('Sprachpfleger, u.a.');
891 expect(mel.children[0].children[0].attributes[0].value).toEqual('author');
hebasta999d6c12018-04-23 12:44:59 +0200892 });
893
894
Akronfa32c9d2018-11-20 15:39:18 +0100895 /* The keywords in the meta information list should be formatted to be able
896 to chose each keyword separately in the corpusByMatch assistant. */
897 it('keywords should be formatted', function(){
hebasta999d6c12018-04-23 12:44:59 +0200898
Akronfa32c9d2018-11-20 15:39:18 +0100899 //type:string or type:keyword should b not relevant
900 expect(mel.children[1].children[1].getAttribute('data-type')).toEqual('type:string')
901 expect(mel.children[1].children[1].classList.contains('metakeyvalues')).toBeTruthy;
902 expect(mel.children[1].children[1].children[0].tagName).toEqual('DIV');
903 expect(mel.children[1].children[1].children[0].firstChild.nodeValue).toEqual('corenlp');
904 expect(mel.children[1].children[1].children[1].tagName).toEqual('DIV');
905 expect(mel.children[1].children[1].children[1].firstChild.nodeValue).toEqual('corenlp\/constituency');
906
907 expect(mel.children[2].children[1].classList.contains('metakeyvalues')).toBeTruthy;
908 expect(mel.children[2].children[1].children[0].tagName).toEqual('DIV');
909 expect(mel.children[2].children[1].children[0].firstChild.nodeValue).toEqual('kultur');
910 expect(mel.children[2].children[1].children[1].tagName).toEqual('DIV');
911 expect(mel.children[2].children[1].children[1].firstChild.nodeValue).toEqual('film');
hebasta999d6c12018-04-23 12:44:59 +0200912 });
Akrona0ea3c32018-12-14 18:33:48 +0100913
914 it('attachements should be formatted', function(){
Akron0f700762022-01-11 17:21:16 +0100915 //type:attachement with a link (legacy)
Akrona0ea3c32018-12-14 18:33:48 +0100916 expect(mel.children[3].children[1].getAttribute('data-type')).toEqual('type:attachement')
Akron0f700762022-01-11 17:21:16 +0100917 expect(mel.children[3].children[1].classList.contains('metakeyvalues')).toBeFalsy;
918 expect(mel.children[3].children[0].firstChild.nodeValue).toEqual('xlink');
919 expect(mel.children[3].children[1].firstChild.textContent).toEqual('Cool');
920 expect(mel.children[3].children[1].firstChild.tagName).toEqual('A');
Akrona0ea3c32018-12-14 18:33:48 +0100921 expect(mel.children[3].children[1].firstChild.getAttribute('href')).toEqual('https://de.wikipedia.org/wiki/Beispiel');
Akrond3bb85b2019-02-08 10:15:13 +0100922
Akron0f700762022-01-11 17:21:16 +0100923 //type:attachement with a link (uri encoded)
Akrond3bb85b2019-02-08 10:15:13 +0100924 expect(mel.children[4].children[1].getAttribute('data-type')).toEqual('type:attachement')
Akron0f700762022-01-11 17:21:16 +0100925 expect(mel.children[4].children[1].classList.contains('metakeyvalues')).toBeFalsy;
926 expect(mel.children[4].children[0].firstChild.nodeValue).toEqual('xlink2');
927 expect(mel.children[4].children[1].firstChild.textContent).toEqual('Hallo!');
928 expect(mel.children[4].children[1].firstChild.tagName).toEqual('A');
929 expect(mel.children[4].children[1].firstChild.getAttribute('href')).toEqual('https://www.test.de');
930
931 //type:attachement with plain text
932 expect(mel.children[5].children[1].getAttribute('data-type')).toEqual('type:attachement')
933 expect(mel.children[5].children[1].classList.contains('metakeyvalues')).toBeFalsy;
934 expect(mel.children[5].children[0].firstChild.nodeValue).toEqual('z-reference');
935 expect(mel.children[5].children[1].firstChild.nodeValue).toEqual('This is a reference');
Akrond3bb85b2019-02-08 10:15:13 +0100936 });
Akrona0ea3c32018-12-14 18:33:48 +0100937
938
hebasta999d6c12018-04-23 12:44:59 +0200939
Akronfa32c9d2018-11-20 15:39:18 +0100940 // Meta information should be sorted alphabetically
941 it('should be alphabetically sorted', function(){
942 var a = mel.children[0].children[0].firstChild.nodeValue;
943 var b = mel.children[1].children[0].firstChild.nodeValue;
944 var c = mel.children[2].children[0].firstChild.nodeValue;
945 expect(a.localeCompare(b)).toBe(-1);
946 expect(b.localeCompare(c)).toBe(-1);
Akrona0ea3c32018-12-14 18:33:48 +0100947 });
948
949
950 it('should handle attachements', function () {
951 let uri = attachementClass.create("data:text/plain;title=new,Hallo");
952 expect(uri.contentType).toEqual("text/plain");
953
954 expect(uri.payload).toEqual("Hallo");
955 expect(uri.base64).toBeFalsy();
956 expect(uri.isLink).toBeFalsy();
957 expect(uri.param["title"]).toEqual("new");
958
959 uri = attachementClass.create("data:application/x.korap-link,https://de.wikipedia.org/wiki/Beispiel");
960 expect(uri.contentType).toEqual("application/x.korap-link");
961 expect(uri.payload).toEqual("https://de.wikipedia.org/wiki/Beispiel");
962 expect(uri.base64).toBeFalsy();
963 expect(uri.isLink).toBeTruthy();
964 expect(uri.inline().textContent).toEqual("https://de.wikipedia.org/wiki/Beispiel");
965 expect(uri.inline().nodeType).toEqual(1);
966 expect(uri.inline().tagName).toEqual("A");
967 expect(uri.inline().getAttribute("rel")).toEqual("noopener noreferrer");
968
969
970 uri = attachementClass.create("data:application/x.korap-link;title=Das ist ein Titel,https://de.wikipedia.org/wiki/Beispiel");
971 expect(uri.contentType).toEqual("application/x.korap-link");
972 expect(uri.payload).toEqual("https://de.wikipedia.org/wiki/Beispiel");
973 expect(uri.base64).toBeFalsy();
974 expect(uri.isLink).toBeTruthy();
975 expect(uri.inline().textContent).toEqual("Das ist ein Titel");
976 expect(uri.inline().nodeType).toEqual(1);
977 expect(uri.inline().tagName).toEqual("A");
978 expect(uri.inline().getAttribute("rel")).toEqual("noopener noreferrer");
979
980
981 uri = attachementClass.create("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D");
982 expect(uri.contentType).toEqual("text/plain");
983 expect(uri.payload).toEqual("Hello, World!");
984 expect(uri.base64).toBeTruthy();
985 expect(uri.isLink).toBeFalsy();
986 expect(uri.inline().nodeType).toEqual(3);
987 expect(uri.inline().textContent).toEqual("Hello, World!");
988
989 uri = attachementClass.create("data:text/plain;title= new ; subTitle = old ;base64,SGVsbG8sIFdvcmxkIQ%3D%3D");
990 expect(uri.contentType).toEqual("text/plain");
991 expect(uri.payload).toEqual("Hello, World!");
992 expect(uri.param["title"]).toEqual("new");
993 expect(uri.param["subTitle"]).toEqual("old");
994 expect(uri.base64).toBeTruthy();
995 expect(uri.isLink).toBeFalsy();
996 expect(uri.inline().nodeType).toEqual(3);
997 expect(uri.inline().textContent).toEqual("Hello, World!");
998 });
hebasta999d6c12018-04-23 12:44:59 +0200999 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001000 // table = view.toTable();
1001 // table.sortBy('');
1002 // table.element();
1003 // tree = view.toTree();
1004 // tree.element();
Nils Diewalda297f062015-04-02 00:23:46 +00001005});