blob: ddd482dbd6d67a8e48b4993762f2f271fbcb3802 [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",
93 "key": "z-reference",
94 "type": "type:attachement",
95 "value": "data:,This is a reference"
96 }
Akrond8692de2018-07-26 13:06:01 +020097 ];
98
99
Akron5dc31172019-05-15 18:43:48 +0200100 var snippet = "<span class=\"context-left\"><\/span>"+
101 "<span class=\"match\">" +
Akron1a780fe2019-05-21 15:59:00 +0200102 "<span class=\"cutted\"><\/span>" +
103 "Außerdem " +
Akron5dc31172019-05-15 18:43:48 +0200104 "<span title=\"cnx/l:meist\">" +
Akrond8692de2018-07-26 13:06:01 +0200105 " <span title=\"cnx/p:ADV\">" +
106 " <span title=\"cnx/syn:@PREMOD\">" +
107 " <span title=\"mate/l:meist\">" +
108 " <span title=\"mate/l:meist\">" +
109 " <span title=\"mate/p:ADV\">" +
110 " <span title=\"opennlp/p:ADV\">meist</span>" +
111 " </span>" +
112 " </span>" +
113 " </span>" +
114 " </span>" +
115 " </span>" +
116 "</span>" +
Akronad1e46a2018-09-19 15:55:40 +0200117 "<mark>" +
Akrond8692de2018-07-26 13:06:01 +0200118 "<span title=\"cnx/l:deutlich\">" +
119 " <span title=\"cnx/p:A\">" +
120 " <span title=\"cnx/syn:@PREMOD\">" +
121 " <span title=\"mate/l:deutlich\">" +
122 " <span title=\"mate/m:degree:pos\">" +
123 " <span title=\"mate/p:ADJD\">" +
124 " <span title=\"opennlp/p:ADJD\">deutlich</span>" +
125 " </span>" +
126 " </span>" +
127 " </span>" +
128 " </span>" +
129 " </span>" +
130 "</span>" +
Akronad1e46a2018-09-19 15:55:40 +0200131 "</mark>" +
Akron158fce12019-12-17 14:43:29 +0100132 "<span title=\"dgd/para:incident\">▮</span>" +
Akrond8692de2018-07-26 13:06:01 +0200133 "<span title=\"cnx/l:fähig\">" +
134 " <span title=\"cnx/l:leistung\">" +
135 " <span title=\"cnx/p:A\">" +
136 " <span title=\"cnx/p:ADJA\">" +
137 " <span title=\"cnx/syn:@NH\">" +
138 " <span title=\"mate/l:leistungsfähig\">" +
139 " <span title=\"mate/m:degree:comp\">" +
140 " <span title=\"mate/p:ADJD\">" +
141 " <span title=\"opennlp/p:ADJD\">leistungsfähiger</span>" +
142 " </span>" +
143 " </span>" +
144 " </span>" +
145 " </span>" +
146 " </span>" +
147 " </span>" +
148 " </span>" +
Akron5dc31172019-05-15 18:43:48 +0200149 "</span>" +
150 " und robust sind auch die anderen Traktoren, die hier der Übersicht wegen keine Erwähnung finden können." +
151 "<span class=\"cutted\"><\/span>" +
Akrond8692de2018-07-26 13:06:01 +0200152 "</span>";
153
154 var treeSnippet =
155 "<span class=\"context-left\"></span>" +
156 "<span class=\"match\">" +
157 " <span title=\"xip/c:MC\">" +
158 " <span title=\"xip/c:TOP\">" +
159 " <span title=\"xip/c:PP\">" +
160 " <span title=\"xip/c:PREP\">Mit</span>" +
161 " <span title=\"xip/c:NP\">" +
162 " <span title=\"xip/c:DET\">dieser</span>" +
163 " <span title=\"xip/c:NPA\">" +
164 " <span title=\"xip/c:NOUN\">Methode</span>" +
165 " </span>" +
166 " </span>" +
167 " </span>" +
168 " <span title=\"xip/c:VERB\">ist</span>" +
169 " <mark>" +
170 " <span title=\"xip/c:NP\">" +
171 " <span title=\"xip/c:PRON\">es</span>" +
172 " </span>" +
173 " <span title=\"xip/c:AP\">" +
174 " <span title=\"xip/c:ADV\">nun</span>" +
175 " <span title=\"xip/c:ADJ\">möglich</span>" +
176 " </span>" +
177 " </mark>" +
178 " <span title=\"xip/c:ADV\">z. B.</span>" +
179 " <span title=\"xip/c:NPA\">" +
180 " <span title=\"xip/c:NP\">" +
181 " <span title=\"xip/c:NOUN\">Voice</span>" +
182 " </span>" +
183 " </span>" + "(" +
184 " <span title=\"xip/c:INS\">" +
185 " <span title=\"xip/c:NPA\">" +
186 " <span title=\"xip/c:NP\">" +
187 " <span title=\"xip/c:NOUN\">Sprache</span>" +
188 " </span>" +
189 " </span>" +
190 " </span>" + ")" +
191 " <span title=\"xip/c:VERB\">bevorzugt</span>" +
192 " <span title=\"xip/c:PP\">" +
193 " <span title=\"xip/c:PREP\">in</span>" +
194 " <span title=\"xip/c:NP\">" +
195 " <span title=\"xip/c:PRON\">der</span>" +
196 " </span>" +
197 " <span title=\"xip/c:NPA\">" +
198 " <span title=\"xip/c:NP\">" +
199 " <span title=\"xip/c:NOUN\">Bridge</span>" +
200 " </span>" +
201 " </span>" +
202 " </span>" +
203 " <span title=\"xip/c:INFC\">" +
204 " <span title=\"xip/c:INS\">" +
205 " <span title=\"xip/c:VERB\">weiterzugeben</span>" +
206 " </span>" +
207 " </span>" +
208 " </span>" +
209 " </span>" +
210 "</span>" +
211 "<span class=\"context-right\"></span>";
212
Akron3bdac532019-03-04 13:24:43 +0100213 var treeSnippetHierarchy =
214 "<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 +0200215
Akron158fce12019-12-17 14:43:29 +0100216 function matchElementFactory () {
Akrond8692de2018-07-26 13:06:01 +0200217 var me = document.createElement('li');
218
219 me.setAttribute(
220 'data-available-info',
221 'base/s=spans corenlp/c=spans corenlp/ne=tokens corenlp/p=tokens' +
222 ' corenlp/s=spans glemm/l=tokens mate/l=tokens mate/m=tokens' +
223 ' mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens' +
224 ' tt/p=tokens tt/s=spans');
225
226 me.setAttribute('data-corpus-id', 'WPD');
227 me.setAttribute('data-doc-id', 'FFF');
228 me.setAttribute('data-text-id', '01460');
229 me.setAttribute('data-text-sigle', 'WPD/FFF/01460');
230 me.setAttribute('data-match-id', 'p119-120');
231 me.innerHTML = '<div><div class="snippet">check</div></div><p class="ref">me</p>';
232 return me;
233 };
234
235 function matchElementReal () {
236 var me = document.createElement('em');
237 me.innerHTML =
238 '<li data-match-id="p85183-85184"' +
239 ' data-text-sigle="GOE/AGI/00000"' +
240 ' 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"' +
241 ' 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;}"' +
242 ' id="GOE/AGI/00000#p85183-85184">' +
243 '<div>' +
244 '<div class="flag"></div>' +
245 '<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>' +
246 '</div>' +
247 '<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>' +
248 '</li>';
249 return me.firstChild;
250 };
251
252 var beforeAllFunc = function () {
253 // Override getMatchInfo API call
254 KorAP.API.getMatchInfo = function (x, param, cb) {
255 if (param['spans'] === undefined || param['spans'] === false)
256 cb({ "snippet": snippet });
257 else
258 cb({ "snippet": treeSnippet });
259 };
260 };
261
262 var afterAllFunc = function () {
263 KorAP.API.getMatchInfo = undefined;
hebasta87f1b1f2019-07-30 13:03:23 +0200264 KorAP.TreeMenu = undefined;
Akrond8692de2018-07-26 13:06:01 +0200265 var body = document.body;
hebasta87f1b1f2019-07-30 13:03:23 +0200266 var i = body.children.length - 1;
267 while (i >= 0) {
Akrond8692de2018-07-26 13:06:01 +0200268 if (body.children[i].nodeType && body.children[i].nodeType === 1) {
269 if (!body.children[i].classList.contains("jasmine_html-reporter")) {
270 body.removeChild(body.children[i]);
271 };
272 };
hebasta87f1b1f2019-07-30 13:03:23 +0200273 i--;
Akrond8692de2018-07-26 13:06:01 +0200274 };
275 };
Akron671fdb92017-09-12 18:09:46 +0200276
Nils Diewald7c8ced22015-04-15 19:21:00 +0000277 describe('KorAP.InfoLayer', function () {
Akrond8692de2018-07-26 13:06:01 +0200278 beforeAll(beforeAllFunc);
279 afterAll(afterAllFunc);
Nils Diewalda297f062015-04-02 00:23:46 +0000280
Nils Diewald7c8ced22015-04-15 19:21:00 +0000281 it('should be initializable', function () {
282 expect(
Akron671fdb92017-09-12 18:09:46 +0200283 function() { infoClass.create() }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000284 ).toThrow(new Error("Missing parameters"));
Nils Diewalda297f062015-04-02 00:23:46 +0000285
Nils Diewald7c8ced22015-04-15 19:21:00 +0000286 expect(
Akron671fdb92017-09-12 18:09:46 +0200287 function() { infoClass.create("base") }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000288 ).toThrow(new Error("Missing parameters"));
Nils Diewalda297f062015-04-02 00:23:46 +0000289
Nils Diewald7c8ced22015-04-15 19:21:00 +0000290 var layer = infoClass.create("base", "s");
291 expect(layer).toBeTruthy();
292 expect(layer.foundry).toEqual("base");
293 expect(layer.layer).toEqual("s");
294 expect(layer.type).toEqual("tokens");
Nils Diewalda297f062015-04-02 00:23:46 +0000295
Nils Diewald7c8ced22015-04-15 19:21:00 +0000296 layer = infoClass.create("cnx", "syn", "spans");
297 expect(layer).toBeTruthy();
298 expect(layer.foundry).toEqual("cnx");
299 expect(layer.layer).toEqual("syn");
300 expect(layer.type).toEqual("spans");
Nils Diewald58141332015-04-07 16:18:45 +0000301 });
302 });
Nils Diewalda297f062015-04-02 00:23:46 +0000303
Nils Diewalda297f062015-04-02 00:23:46 +0000304
Nils Diewald7c8ced22015-04-15 19:21:00 +0000305 describe('KorAP.Match', function () {
Akrond8692de2018-07-26 13:06:01 +0200306 beforeAll(beforeAllFunc);
307 afterAll(afterAllFunc);
308
Nils Diewald7c8ced22015-04-15 19:21:00 +0000309 var match = {
310 'corpusID' : 'WPD',
311 'docID' : 'UUU',
312 'textID' : '01912',
313 'matchID' : 'p121-122',
Akron0a6768f2016-07-13 18:00:43 +0200314 'textSigle' : 'WPD/UUU/01912',
Nils Diewald7c8ced22015-04-15 19:21:00 +0000315 'available' : available
316 };
317
Nils Diewald7c8ced22015-04-15 19:21:00 +0000318 it('should be initializable by Object', function () {
319 expect(function() {
Akron671fdb92017-09-12 18:09:46 +0200320 matchClass.create()
Nils Diewald7c8ced22015-04-15 19:21:00 +0000321 }).toThrow(new Error('Missing parameters'));
322
323 expect(matchClass.create(match)).toBeTruthy();
324
325 var m = matchClass.create(match);
Akron0a6768f2016-07-13 18:00:43 +0200326 expect(m.textSigle).toEqual("WPD/UUU/01912");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000327 expect(m.matchID).toEqual("p121-122");
328
329 // /corpus/WPD/UUU.01912/p121-122/matchInfo?spans=false&foundry=*
330 var m = matchClass.create(match);
331
332 // Spans:
333 var spans = m.getSpans();
334 expect(spans[0].foundry).toEqual("base");
335 expect(spans[0].layer).toEqual("s");
336
337 expect(spans[1].foundry).toEqual("corenlp");
338 expect(spans[1].layer).toEqual("c");
339
340 expect(spans[2].foundry).toEqual("corenlp");
341 expect(spans[2].layer).toEqual("s");
342
343 expect(spans[spans.length-1].foundry).toEqual("tt");
344 expect(spans[spans.length-1].layer).toEqual("s");
345
346 // Tokens:
347 var tokens = m.getTokens();
348 expect(tokens[0].foundry).toEqual("corenlp");
349 expect(tokens[0].layer).toEqual("ne");
350
351 expect(tokens[1].foundry).toEqual("corenlp");
352 expect(tokens[1].layer).toEqual("p");
353
354 expect(tokens[tokens.length-1].foundry).toEqual("tt");
355 expect(tokens[tokens.length-1].layer).toEqual("p");
Nils Diewald58141332015-04-07 16:18:45 +0000356 });
Nils Diewalda297f062015-04-02 00:23:46 +0000357
358
Akroncdb0baa2016-11-07 01:52:11 +0100359 it('should be initializable by Node 1', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000360 var m = matchClass.create(matchElementFactory());
Akron0a6768f2016-07-13 18:00:43 +0200361 expect(m.textSigle).toEqual("WPD/FFF/01460");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000362 expect(m.matchID).toEqual("p119-120");
Nils Diewalda297f062015-04-02 00:23:46 +0000363
Nils Diewald7c8ced22015-04-15 19:21:00 +0000364 // Spans:
365 var spans = m.getSpans();
366 expect(spans[0].foundry).toEqual("base");
367 expect(spans[0].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000368
Nils Diewald7c8ced22015-04-15 19:21:00 +0000369 expect(spans[1].foundry).toEqual("corenlp");
370 expect(spans[1].layer).toEqual("c");
Nils Diewalda297f062015-04-02 00:23:46 +0000371
Nils Diewald7c8ced22015-04-15 19:21:00 +0000372 expect(spans[2].foundry).toEqual("corenlp");
373 expect(spans[2].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000374
Nils Diewald7c8ced22015-04-15 19:21:00 +0000375 expect(spans[spans.length-1].foundry).toEqual("tt");
376 expect(spans[spans.length-1].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000377
Nils Diewald7c8ced22015-04-15 19:21:00 +0000378 // Tokens:
379 var tokens = m.getTokens();
380 expect(tokens[0].foundry).toEqual("corenlp");
381 expect(tokens[0].layer).toEqual("ne");
Nils Diewalda297f062015-04-02 00:23:46 +0000382
Nils Diewald7c8ced22015-04-15 19:21:00 +0000383 expect(tokens[1].foundry).toEqual("corenlp");
384 expect(tokens[1].layer).toEqual("p");
Nils Diewalda297f062015-04-02 00:23:46 +0000385
Nils Diewald7c8ced22015-04-15 19:21:00 +0000386 expect(tokens[tokens.length-1].foundry).toEqual("tt");
387 expect(tokens[tokens.length-1].layer).toEqual("p");
Nils Diewalda297f062015-04-02 00:23:46 +0000388
Nils Diewald7c8ced22015-04-15 19:21:00 +0000389 });
Nils Diewalda297f062015-04-02 00:23:46 +0000390
Akroncdb0baa2016-11-07 01:52:11 +0100391 it('should be initializable by Node 2', function () {
392 var ele = matchElementReal();
393 var m = matchClass.create(ele);
394 expect(m.textSigle).toEqual("GOE/AGI/00000");
395 expect(m.matchID).toEqual("p85183-85184");
396 });
397
Akron3c390c42020-03-30 09:06:21 +0200398 it('should be initializable when active', function () {
399 var e = matchElementFactory();
400 e.setAttribute('class', 'active');
401
402 expect(e.classList.contains('active')).toBe(true);
403 expect(e["_match"]).toBe(undefined);
404
405 var m = matchClass.create(e);
406
407 expect(e["_match"]).not.toBe(undefined);
408
409 // Open the match
410 m.init();
411
412 expect(e["_match"]).not.toBe(undefined);
413
414 actions = e.querySelector("p.ref > div.action.button-group").children;
415
416 expect(actions[0].getAttribute("class")).toEqual("metatable");
417 expect(actions[1].getAttribute("class")).toEqual("info");
418 expect(actions[2].getAttribute("class")).toEqual("tree");
419
420 // Close the match
421 expect(e.querySelector("div.action.button-group > span.minimize")).toBe(null);
422 });
Akroncdb0baa2016-11-07 01:52:11 +0100423
Nils Diewald7c8ced22015-04-15 19:21:00 +0000424 it('should react to gui actions', function () {
425 var e = matchElementFactory();
Nils Diewalda297f062015-04-02 00:23:46 +0000426
Nils Diewald7c8ced22015-04-15 19:21:00 +0000427 expect(e.classList.contains('active')).toBe(false);
428 expect(e["_match"]).toBe(undefined);
Nils Diewalda297f062015-04-02 00:23:46 +0000429
Nils Diewald7c8ced22015-04-15 19:21:00 +0000430 var m = matchClass.create(e);
431
432 expect(e.classList.contains('active')).toBe(false);
433 expect(e["_match"]).not.toBe(undefined);
hebasta87f1b1f2019-07-30 13:03:23 +0200434
Nils Diewald7c8ced22015-04-15 19:21:00 +0000435 // Open the match
436 m.open();
hebasta87f1b1f2019-07-30 13:03:23 +0200437
Nils Diewald7c8ced22015-04-15 19:21:00 +0000438 expect(e.classList.contains('active')).toBe(true);
439 expect(e["_match"]).not.toBe(undefined);
440
Akronbfe912c2018-07-17 19:30:52 +0200441 actions = e.querySelector("p.ref > div.action.button-group").children;
Akrond141a362018-07-10 18:12:13 +0200442
Akronbfe912c2018-07-17 19:30:52 +0200443 expect(actions[0].getAttribute("class")).toEqual("metatable");
Akronc296ca22018-04-24 16:35:26 +0200444 expect(actions[1].getAttribute("class")).toEqual("info");
445 expect(actions[2].getAttribute("class")).toEqual("tree");
Akron3c390c42020-03-30 09:06:21 +0200446
447 expect(e.querySelector("div.action.button-group > span.minimize")).not.toBe(null);
Akronc296ca22018-04-24 16:35:26 +0200448
Nils Diewald7c8ced22015-04-15 19:21:00 +0000449 // Close the match
Akronec6bb8e2018-08-29 13:07:56 +0200450 m.minimize();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000451 expect(e.classList.contains('active')).toBe(false);
452 expect(e["_match"]).not.toBe(undefined);
Nils Diewald58141332015-04-07 16:18:45 +0000453 });
Akron3c390c42020-03-30 09:06:21 +0200454
Akrond8692de2018-07-26 13:06:01 +0200455 it('should open tree menu', function () {
Akronc296ca22018-04-24 16:35:26 +0200456 var e = matchElementFactory();
457 var m = matchClass.create(e);
458 m.open();
Akronbfe912c2018-07-17 19:30:52 +0200459 var relation = e.querySelector("p.ref > div.action.button-group > span:nth-of-type(3)");
Akronc296ca22018-04-24 16:35:26 +0200460 expect(relation.getAttribute("class")).toEqual("tree");
Akron52ed22d2018-07-11 17:05:19 +0200461 expect(document.getElementsByClassName("button-group-list").length).toEqual(0);
Akronc296ca22018-04-24 16:35:26 +0200462 expect(document.activeElement.tagName).toEqual("BODY");
hebasta87f1b1f2019-07-30 13:03:23 +0200463
Akronc296ca22018-04-24 16:35:26 +0200464 // Show menu
465 relation.click();
Akron52ed22d2018-07-11 17:05:19 +0200466 expect(document.getElementsByClassName("button-group-list").length).toEqual(1);
Akronc296ca22018-04-24 16:35:26 +0200467 expect(document.activeElement.tagName).toEqual("UL");
hebasta87f1b1f2019-07-30 13:03:23 +0200468
Akronc296ca22018-04-24 16:35:26 +0200469 // Choose first tree
Akron52ed22d2018-07-11 17:05:19 +0200470 document.getElementsByClassName("button-group-list")[0].getElementsByTagName("li")[1].click();
Akronc296ca22018-04-24 16:35:26 +0200471 expect(e.querySelector("div.matchinfo div.matchtree h6 span").innerText).toEqual("corenlp");
472
473 // This should blur the focus
474 expect(document.activeElement.tagName).toEqual("BODY");
hebasta87f1b1f2019-07-30 13:03:23 +0200475
Akronc296ca22018-04-24 16:35:26 +0200476 });
477
478 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000479
Akron7f9a6a32018-07-18 15:05:23 +0200480 describe('KorAP.TableView', function () {
Akrond8692de2018-07-26 13:06:01 +0200481 beforeAll(beforeAllFunc);
482 afterAll(afterAllFunc);
Akron5dc31172019-05-15 18:43:48 +0200483
484 let longString = " und robust sind auch die anderen Traktoren, die hier der Übersicht wegen keine Erwähnung finden können.";
485
Akron7f9a6a32018-07-18 15:05:23 +0200486 var table;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000487
Akron7f9a6a32018-07-18 15:05:23 +0200488 var matchObj = matchClass.create(match);
489 var tableObj = tableClass.create(matchObj);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000490
491 var table1, table2;
492
Nils Diewald7c8ced22015-04-15 19:21:00 +0000493 it('should fail to load a table async', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200494 expect(tableObj).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000495
Akron7f9a6a32018-07-18 15:05:23 +0200496 tableObj.getData([], function (tablen) {
Akron671fdb92017-09-12 18:09:46 +0200497 table1 = tablen;
498 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000499 });
500 });
501
Akron671fdb92017-09-12 18:09:46 +0200502
Akronaeeb8252018-09-19 18:51:00 +0200503 xit('should\'nt be parsable (async)', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000504 expect(table1).not.toBeTruthy();
505 });
506
Nils Diewald7c8ced22015-04-15 19:21:00 +0000507
Nils Diewald7c8ced22015-04-15 19:21:00 +0000508 it('should be retrieved async', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200509 expect(tableObj).toBeTruthy();
510 tableObj.getData(undefined, function (x) {
Akron671fdb92017-09-12 18:09:46 +0200511 table = x;
512 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000513 });
514 });
Nils Diewalda297f062015-04-02 00:23:46 +0000515
Akron7f9a6a32018-07-18 15:05:23 +0200516 it('should parse into a table (async)', function () {
517 expect(table).toBeTruthy();
Akron5b1a6af2018-02-05 15:41:16 +0100518
Akron158fce12019-12-17 14:43:29 +0100519 expect(table.length()).toBe(8);
Akron7f9a6a32018-07-18 15:05:23 +0200520
Akron1a780fe2019-05-21 15:59:00 +0200521 expect(table.getToken(0)).toBe("");
522 expect(table.getToken(1)).toBe("Außerdem ");
523 expect(table.getToken(2)).toBe("meist");
524 expect(table.getToken(3)).toBe("deutlich");
Akron158fce12019-12-17 14:43:29 +0100525 expect(table.getToken(5)).toBe("leistungsfähiger");
526 expect(table.getToken(6)).toBe(longString);
Akron7f9a6a32018-07-18 15:05:23 +0200527
Akron1a780fe2019-05-21 15:59:00 +0200528 expect(table.getValue(2, "cnx", "p")[0]).toBe("ADV");
529 expect(table.getValue(2, "cnx", "syn")[0]).toBe("@PREMOD");
530 expect(table.getValue(2, "mate", "l")[0]).toBe("meist");
531 expect(table.getValue(2, "mate", "l")[1]).toBeUndefined();
Akron7f9a6a32018-07-18 15:05:23 +0200532
Akron158fce12019-12-17 14:43:29 +0100533 expect(table.getValue(5, "cnx", "l")[0]).toBe("fähig");
534 expect(table.getValue(5, "cnx", "l")[1]).toBe("leistung");
Akron7f9a6a32018-07-18 15:05:23 +0200535 });
536
537 it('should be rendered async', function () {
Akron5b1a6af2018-02-05 15:41:16 +0100538 var e = table.element().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000539 expect(e.nodeName).toBe('TABLE');
540 expect(e.children[0].nodeName).toBe('THEAD');
541 var tr = e.children[0].children[0];
542 expect(tr.nodeName).toBe('TR');
543 expect(tr.children[0].nodeName).toBe('TH');
Nils Diewald58141332015-04-07 16:18:45 +0000544
Nils Diewald7c8ced22015-04-15 19:21:00 +0000545 expect(tr.children[0].firstChild.nodeValue).toBe('Foundry');
546 expect(tr.children[1].firstChild.nodeValue).toBe('Layer');
Akron1a780fe2019-05-21 15:59:00 +0200547
548 expect(tr.children[2].classList.contains('cutted')).toBeTruthy();
549 expect(tr.children[3].firstChild.nodeValue).toBe('Außerdem ');
550
551
552 expect(tr.children[4].firstChild.nodeValue).toBe('meist');
Akronad1e46a2018-09-19 15:55:40 +0200553 expect(tr.children[4].classList.contains('mark')).toBeFalsy();
Akron1a780fe2019-05-21 15:59:00 +0200554 expect(tr.children[5].firstChild.nodeValue).toBe('deutlich');
555 expect(tr.children[5].classList.contains('mark')).toBeTruthy();
Akron158fce12019-12-17 14:43:29 +0100556 expect(tr.children[6].firstChild.nodeValue).toBe('▮');
557 expect(tr.children[7].firstChild.nodeValue).toBe('leistungsfähiger');
558 expect(tr.children[7].classList.contains('mark')).toBeFalsy();
559 expect(tr.children[7].hasAttribute("title")).toBeFalsy();
560 expect(tr.children[8].firstChild.nodeValue).toBe(longString);
561 expect(tr.children[8].getAttribute("title")).toBe(longString);
562 expect(tr.children[9].classList.contains('cutted')).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000563
564 // first row
565 tr = e.children[1].children[0];
566 expect(tr.nodeName).toBe('TR');
567 expect(tr.getAttribute('tabindex')).toEqual('0');
568 expect(tr.children[0].nodeName).toBe('TH');
569 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
570 expect(tr.children[1].firstChild.nodeValue).toEqual('l');
Akron1a780fe2019-05-21 15:59:00 +0200571 expect(tr.children[4].firstChild.nodeValue).toEqual('meist');
572 expect(tr.children[5].firstChild.nodeValue).toEqual('deutlich');
Akron158fce12019-12-17 14:43:29 +0100573 expect(tr.children[6].firstChild).toBeNull();
574 expect(tr.children[7].firstChild.firstChild.nodeValue).toEqual('fähig');
575 expect(tr.children[7].lastChild.firstChild.nodeValue).toEqual('leistung');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000576
577 // second row
578 tr = e.children[1].children[1];
579 expect(tr.nodeName).toBe('TR');
580 expect(tr.getAttribute('tabindex')).toEqual('0');
581 expect(tr.children[0].nodeName).toBe('TH');
582 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
583 expect(tr.children[1].firstChild.nodeValue).toEqual('p');
Akron1a780fe2019-05-21 15:59:00 +0200584 expect(tr.children[4].firstChild.nodeValue).toEqual('ADV');
585 expect(tr.children[5].firstChild.nodeValue).toEqual('A');
Akron158fce12019-12-17 14:43:29 +0100586 expect(tr.children[6].firstChild).toBeNull();
587 expect(tr.children[7].firstChild.firstChild.nodeValue).toEqual('A');
588 expect(tr.children[7].lastChild.firstChild.nodeValue).toEqual('ADJA');
Akronf2279c42017-12-21 13:48:46 +0100589
Akron158fce12019-12-17 14:43:29 +0100590 expect(tr.children[7].firstChild.getAttribute("title")).toEqual('Adjective');
Akron1a780fe2019-05-21 15:59:00 +0200591 expect(tr.children[4].getAttribute("title")).toEqual('Adverb');
Nils Diewald58141332015-04-07 16:18:45 +0000592 });
Akron7f9a6a32018-07-18 15:05:23 +0200593
594
595 it('should parse into a table view (sync)', function () {
596 var matchElement = matchElementFactory();
597 expect(matchElement.tagName).toEqual('LI');
598
599 // Match
600 expect(matchElement.children[0].tagName).toEqual('DIV');
601
602 // snippet
603 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
604 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
605 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
606
607 // reference
608 expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
609 expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
610
611 // not yet
612 expect(matchElement.children[0].children[1]).toBe(undefined);
613
614 /*
615 var info = matchClass.create(matchElement).info();
616 info.showTable();
617 */
618 var matchObj = matchClass.create(matchElement);
619 matchObj.open();
620
621 // Match
622 expect(matchElement.children[0].tagName).toEqual('DIV');
623
624 // snippet
625 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
626
627 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
628
629 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
630
631 // reference
632
633 expect(matchElement.children[2].classList.contains('ref')).toBeTruthy();
634 expect(matchElement.children[2].childNodes[1].nodeValue).toEqual('me');
635
636 // Add table
637 matchObj.panel.addTable();
638
639 // now
640 var infotable = matchElement.children[1];
641 expect(infotable.tagName).toEqual('DIV');
642
643 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
644
645 expect(infotable.firstChild.firstChild.firstChild.classList.contains('matchtable')).toBeTruthy();
646
647 // expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
648 });
649
Akron158fce12019-12-17 14:43:29 +0100650 it('should parse into a table view with non-verbal elements (sync)', function () {
651 var matchElement = matchElementFactory();
652 expect(matchElement.tagName).toEqual('LI');
653 });
654
Nils Diewald58141332015-04-07 16:18:45 +0000655 });
Nils Diewalda297f062015-04-02 00:23:46 +0000656
Akron7f9a6a32018-07-18 15:05:23 +0200657 describe('KorAP.RelationsView', function () {
Akrond8692de2018-07-26 13:06:01 +0200658 beforeAll(beforeAllFunc);
659 afterAll(afterAllFunc);
660
Nils Diewald7c8ced22015-04-15 19:21:00 +0000661 var tree;
Nils Diewalda297f062015-04-02 00:23:46 +0000662
Nils Diewald7c8ced22015-04-15 19:21:00 +0000663 it('should be rendered async 1', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200664 var matchObj = matchClass.create(match);
665 var relObj = relClass.create(matchObj);
666 expect(relObj).toBeTruthy();
667 relObj.getData(undefined, undefined, "spans", function (y) {
Akron671fdb92017-09-12 18:09:46 +0200668 tree = y;
669 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000670 });
671 });
Nils Diewalda297f062015-04-02 00:23:46 +0000672
Nils Diewald7c8ced22015-04-15 19:21:00 +0000673 it('should be rendered async 2', function () {
Akron7f9a6a32018-07-18 15:05:23 +0200674 expect(tree).toBeTruthy();
675 expect(tree.nodes()).toEqual(49);
676
Nils Diewald7c8ced22015-04-15 19:21:00 +0000677 var e = tree.element();
678 expect(e.nodeName).toEqual('svg');
679 expect(e.getElementsByTagName('g').length).toEqual(48);
Nils Diewald58141332015-04-07 16:18:45 +0000680 });
Akron7f9a6a32018-07-18 15:05:23 +0200681
682
683 it('should add a tree view async 2', function () {
684 var matchElement = matchElementFactory();
685 var matchObj = matchClass.create(matchElement);
686 matchObj.open();
687 matchObj.panel.addTree('mate', 'beebop', 'spans', function () {
688 done();
689 });
690
691 // With added tree
692 var tree = matchElement.children[1].firstChild.firstChild.firstChild;
693 expect(tree.tagName).toEqual('DIV');
694 expect(tree.classList.contains('matchtree')).toBeTruthy();
695 expect(tree.children[0].tagName).toEqual('H6');
696 expect(tree.children[0].children[0].tagName).toEqual('SPAN');
697 expect(tree.children[0].children[0].firstChild.nodeValue).toEqual('mate');
698 expect(tree.children[0].children[1].tagName).toEqual('SPAN');
699 expect(tree.children[0].children[1].firstChild.nodeValue).toEqual('beebop');
700
701 expect(tree.children[1].tagName).toEqual('DIV');
702 });
703
Akron3bdac532019-03-04 13:24:43 +0100704 it('should make the tree downloadable', function () {
705 var treeClass = matchHierClass.create(treeSnippetHierarchy);
706 var treeElement = treeClass.element();
707 expect(treeElement.tagName).toEqual("svg");
708
709 var base64 = treeClass.toBase64();
710 var str = atob(base64);
711 expect(str).toMatch(new RegExp('<defs><style>path'));
712 expect(str).not.toMatch(new RegExp('&nbsp;'));
713 expect(str).toMatch(new RegExp('&amp;'));
714 });
Nils Diewald58141332015-04-07 16:18:45 +0000715 });
Nils Diewalda297f062015-04-02 00:23:46 +0000716
Nils Diewald7c8ced22015-04-15 19:21:00 +0000717
718 describe('KorAP.MatchTreeItem', function () {
Akrond8692de2018-07-26 13:06:01 +0200719 beforeAll(beforeAllFunc);
720 afterAll(afterAllFunc);
721
Nils Diewald7c8ced22015-04-15 19:21:00 +0000722 it('should be initializable', function () {
723 var mi = matchTreeItemClass.create(['cnx/c', 'cnx', 'c'])
724 expect(mi.element().firstChild.nodeValue).toEqual('cnx/c');
725 expect(mi.lcField()).toEqual(' cnx/c');
726 expect(mi.foundry()).toEqual('cnx');
727 expect(mi.layer()).toEqual('c');
728 });
Nils Diewalda297f062015-04-02 00:23:46 +0000729 });
Nils Diewalda297f062015-04-02 00:23:46 +0000730
731
Akron671fdb92017-09-12 18:09:46 +0200732 describe('KorAP.MatchRelation', function () {
Akrond8692de2018-07-26 13:06:01 +0200733 beforeAll(beforeAllFunc);
734 afterAll(afterAllFunc);
Akron671fdb92017-09-12 18:09:46 +0200735
736 var relExample = "<span class=\"context-left\"></span>" +
737 "<span class=\"match\">" +
738 " <span xml:id=\"token-GOE/AGA/01784-p199\">" +
739 " <span xlink:title=\"malt/d:ADV\" " +
740 " xlink:type=\"simple\" " +
741 " xlink:href=\"#token-GOE/AGA/01784-p199\">dann</span>" +
742 " </span>" +
743 " zog " +
744 " <span xlink:title=\"malt/d:SUBJ\" " +
745 " xlink:type=\"simple\" " +
746 " xlink:href=\"#token-GOE/AGA/01784-p199\">ich</span>" +
747 " <span xml:id=\"token-GOE/AGA/01784-p202\">" +
748 " <span xlink:title=\"malt/d:OBJA\" " +
749 " xlink:type=\"simple\" " +
750 " xlink:href=\"#token-GOE/AGA/01784-p199\">mich</span>" +
751 " </span>" +
752 "</span>" +
753 "<span class=\"context-right\"></span>";
754
755
756 it('should be initializable', function () {
Akrond8692de2018-07-26 13:06:01 +0200757 var tree = matchRelClass.create();
Akron671fdb92017-09-12 18:09:46 +0200758 expect(tree.size()).toBe(0);
759 });
760
761 it('should be parse string data', function () {
Akrond8692de2018-07-26 13:06:01 +0200762 var tree = matchRelClass.create(relExample);
Akron671fdb92017-09-12 18:09:46 +0200763 expect(tree.size()).toBe(4);
764 });
Akron0a785d42020-10-12 17:21:46 +0200765
766 it('should accept missing data', function () {
767 var relExample2 = "<span class=\"context-left\"><\/span>"+
768 "<span class=\"match\">"+
769 "{{"+
770 "<span xml:id=\"token-WUD17\/D95\/09441-p180\">"+
771 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p179\">Wikiläum<\/span>"+
772 "<\/span>"+
773 "|"+
774 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p180\">Silber<\/span>"+
775 "|"+
776 "<span xlink:title=\"malt\/d:DET\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p183\">Dein<\/span>"+
777 " "+
778 "<span xml:id=\"token-WUD17\/D95\/09441-p183\">"+
779 "<span xlink:title=\"malt\/d:ROOT\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p179-196\">Freund<\/span>"+
780 "<\/span>"+
781 " "+
782 "<span xlink:title=\"malt\/d:DET\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p185\">der<\/span>"+
783 " "+
784 "<span xml:id=\"token-WUD17\/D95\/09441-p185-186\">"+
785 "<span xml:id=\"token-WUD17\/D95\/09441-p185\">"+
786 "<mark>"+
787 "<span xlink:title=\"malt\/d:GMOD\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p183\">Baum<\/span>"+
788 "<\/mark>"+
789 "<\/span>"+
790 "| "+
791 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p185-186\">09:38<\/span>"+
792 "<\/span>"+
793 ", "+
794 "<span xlink:title=\"malt\/d:ATTR\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p188\">22.<\/span>"+
795 " "+
796 "<span xml:id=\"token-WUD17\/D95\/09441-p188\">"+
797 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p183\">Aug.<\/span>"+
798 "<\/span>"+
799 " "+
800 "<span xml:id=\"token-WUD17\/D95\/09441-p189\">"+
801 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p188\">2015<\/span>"+
802 "<\/span>"+
803 " ("+
804 "<span xlink:title=\"malt\/d:PAR\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p189\">CEST<\/span>"+
805 ")"+
806 "<\/span>"+
807 "<span class=\"context-right\"><\/span>";
808 var tree = matchRelClass.create(relExample2);
809 expect(tree.size()).toBe(18);
810 var treeElement = tree.element();
811 expect(treeElement.tagName).toEqual("svg");
812 tree.show();
813 expect(treeElement.querySelector("text[text-anchor=\"middle\"]").textContent).toEqual("APP");
814 });
Akron671fdb92017-09-12 18:09:46 +0200815 });
816
817
Nils Diewald7c8ced22015-04-15 19:21:00 +0000818 describe('KorAP.MatchTreeMenu', function () {
Akrond8692de2018-07-26 13:06:01 +0200819 beforeAll(beforeAllFunc);
820 afterAll(afterAllFunc);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000821
822 it('should be initializable', function () {
Akrond8692de2018-07-26 13:06:01 +0200823 var menu = matchTreeMenuClass.create([
Akron671fdb92017-09-12 18:09:46 +0200824 ['cnx/c', 'cnx', 'c'],
825 ['xip/c', 'xip', 'c']
Akrond8692de2018-07-26 13:06:01 +0200826 ], matchTreeItemClass);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000827
Akrond8692de2018-07-26 13:06:01 +0200828 expect(menu.itemClass()).toEqual(matchTreeItemClass);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000829 expect(menu.element().nodeName).toEqual('UL');
Akronaba7a5a2016-08-15 21:58:33 +0200830 expect(menu.element().classList.contains('visible')).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000831 expect(menu.limit()).toEqual(6);
832 menu.show();
Akronaba7a5a2016-08-15 21:58:33 +0200833 expect(menu.element().classList.contains('visible')).toBeTruthy();
Akronc1457bf2015-06-11 19:24:00 +0200834 expect(menu.item(0).active()).toBe(false);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000835 });
Nils Diewalda297f062015-04-02 00:23:46 +0000836 });
hebasta999d6c12018-04-23 12:44:59 +0200837
838 //Test display and sorting of meta information
839 describe('KorAP.Meta', function(){
Akrond8692de2018-07-26 13:06:01 +0200840 beforeAll(beforeAllFunc);
841 afterAll(afterAllFunc);
842
843 var met = metaClass.create(match, fields);
hebasta999d6c12018-04-23 12:44:59 +0200844 var mel = met.element();
845
846 // Meta information should be parsed into a list
847 it('should parse in a meta view', function(){
Akronfa32c9d2018-11-20 15:39:18 +0100848 expect(mel.tagName).toEqual('DL');
849 expect(mel.children[0].tagName).toEqual('DIV');
850 expect(mel.children[0].children[0].tagName).toEqual('DT');
851 expect(mel.children[0].children[0].attributes[0].name).toEqual('title');
852 expect(mel.children[0].children[1].tagName).toEqual('DD');
853 expect(mel.children[0].children[1].getAttribute('data-type')).toEqual('type:text')
hebasta999d6c12018-04-23 12:44:59 +0200854
Akronfa32c9d2018-11-20 15:39:18 +0100855 expect(mel.children[0].children[0].firstChild.nodeValue).toEqual('author');
856 expect(mel.children[0].children[1].firstChild.nodeValue).toEqual('Sprachpfleger, u.a.');
857 expect(mel.children[0].children[0].attributes[0].value).toEqual('author');
hebasta999d6c12018-04-23 12:44:59 +0200858 });
859
860
Akronfa32c9d2018-11-20 15:39:18 +0100861 /* The keywords in the meta information list should be formatted to be able
862 to chose each keyword separately in the corpusByMatch assistant. */
863 it('keywords should be formatted', function(){
hebasta999d6c12018-04-23 12:44:59 +0200864
Akronfa32c9d2018-11-20 15:39:18 +0100865 //type:string or type:keyword should b not relevant
866 expect(mel.children[1].children[1].getAttribute('data-type')).toEqual('type:string')
867 expect(mel.children[1].children[1].classList.contains('metakeyvalues')).toBeTruthy;
868 expect(mel.children[1].children[1].children[0].tagName).toEqual('DIV');
869 expect(mel.children[1].children[1].children[0].firstChild.nodeValue).toEqual('corenlp');
870 expect(mel.children[1].children[1].children[1].tagName).toEqual('DIV');
871 expect(mel.children[1].children[1].children[1].firstChild.nodeValue).toEqual('corenlp\/constituency');
872
873 expect(mel.children[2].children[1].classList.contains('metakeyvalues')).toBeTruthy;
874 expect(mel.children[2].children[1].children[0].tagName).toEqual('DIV');
875 expect(mel.children[2].children[1].children[0].firstChild.nodeValue).toEqual('kultur');
876 expect(mel.children[2].children[1].children[1].tagName).toEqual('DIV');
877 expect(mel.children[2].children[1].children[1].firstChild.nodeValue).toEqual('film');
hebasta999d6c12018-04-23 12:44:59 +0200878 });
Akrona0ea3c32018-12-14 18:33:48 +0100879
880 it('attachements should be formatted', function(){
Akrond3bb85b2019-02-08 10:15:13 +0100881 //type:attachement with a link
Akrona0ea3c32018-12-14 18:33:48 +0100882 expect(mel.children[3].children[1].getAttribute('data-type')).toEqual('type:attachement')
883 expect(mel.children[3].children[1].classList.contains('metakeyvalues')).toBeFalsy;
884 expect(mel.children[3].children[0].firstChild.nodeValue).toEqual('xlink');
885 expect(mel.children[3].children[1].firstChild.textContent).toEqual('Cool');
886 expect(mel.children[3].children[1].firstChild.tagName).toEqual('A');
887 expect(mel.children[3].children[1].firstChild.getAttribute('href')).toEqual('https://de.wikipedia.org/wiki/Beispiel');
Akrond3bb85b2019-02-08 10:15:13 +0100888
889 //type:attachement with plain text
890 expect(mel.children[4].children[1].getAttribute('data-type')).toEqual('type:attachement')
891 expect(mel.children[4].children[1].classList.contains('metakeyvalues')).toBeFalsy;
892 expect(mel.children[4].children[0].firstChild.nodeValue).toEqual('z-reference');
893 expect(mel.children[4].children[1].firstChild.nodeValue).toEqual('This is a reference');
894 });
Akrona0ea3c32018-12-14 18:33:48 +0100895
896
hebasta999d6c12018-04-23 12:44:59 +0200897
Akronfa32c9d2018-11-20 15:39:18 +0100898 // Meta information should be sorted alphabetically
899 it('should be alphabetically sorted', function(){
900 var a = mel.children[0].children[0].firstChild.nodeValue;
901 var b = mel.children[1].children[0].firstChild.nodeValue;
902 var c = mel.children[2].children[0].firstChild.nodeValue;
903 expect(a.localeCompare(b)).toBe(-1);
904 expect(b.localeCompare(c)).toBe(-1);
Akrona0ea3c32018-12-14 18:33:48 +0100905 });
906
907
908 it('should handle attachements', function () {
909 let uri = attachementClass.create("data:text/plain;title=new,Hallo");
910 expect(uri.contentType).toEqual("text/plain");
911
912 expect(uri.payload).toEqual("Hallo");
913 expect(uri.base64).toBeFalsy();
914 expect(uri.isLink).toBeFalsy();
915 expect(uri.param["title"]).toEqual("new");
916
917 uri = attachementClass.create("data:application/x.korap-link,https://de.wikipedia.org/wiki/Beispiel");
918 expect(uri.contentType).toEqual("application/x.korap-link");
919 expect(uri.payload).toEqual("https://de.wikipedia.org/wiki/Beispiel");
920 expect(uri.base64).toBeFalsy();
921 expect(uri.isLink).toBeTruthy();
922 expect(uri.inline().textContent).toEqual("https://de.wikipedia.org/wiki/Beispiel");
923 expect(uri.inline().nodeType).toEqual(1);
924 expect(uri.inline().tagName).toEqual("A");
925 expect(uri.inline().getAttribute("rel")).toEqual("noopener noreferrer");
926
927
928 uri = attachementClass.create("data:application/x.korap-link;title=Das ist ein Titel,https://de.wikipedia.org/wiki/Beispiel");
929 expect(uri.contentType).toEqual("application/x.korap-link");
930 expect(uri.payload).toEqual("https://de.wikipedia.org/wiki/Beispiel");
931 expect(uri.base64).toBeFalsy();
932 expect(uri.isLink).toBeTruthy();
933 expect(uri.inline().textContent).toEqual("Das ist ein Titel");
934 expect(uri.inline().nodeType).toEqual(1);
935 expect(uri.inline().tagName).toEqual("A");
936 expect(uri.inline().getAttribute("rel")).toEqual("noopener noreferrer");
937
938
939 uri = attachementClass.create("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D");
940 expect(uri.contentType).toEqual("text/plain");
941 expect(uri.payload).toEqual("Hello, World!");
942 expect(uri.base64).toBeTruthy();
943 expect(uri.isLink).toBeFalsy();
944 expect(uri.inline().nodeType).toEqual(3);
945 expect(uri.inline().textContent).toEqual("Hello, World!");
946
947 uri = attachementClass.create("data:text/plain;title= new ; subTitle = old ;base64,SGVsbG8sIFdvcmxkIQ%3D%3D");
948 expect(uri.contentType).toEqual("text/plain");
949 expect(uri.payload).toEqual("Hello, World!");
950 expect(uri.param["title"]).toEqual("new");
951 expect(uri.param["subTitle"]).toEqual("old");
952 expect(uri.base64).toBeTruthy();
953 expect(uri.isLink).toBeFalsy();
954 expect(uri.inline().nodeType).toEqual(3);
955 expect(uri.inline().textContent).toEqual("Hello, World!");
956 });
hebasta999d6c12018-04-23 12:44:59 +0200957 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000958 // table = view.toTable();
959 // table.sortBy('');
960 // table.element();
961 // tree = view.toTree();
962 // tree.element();
Nils Diewalda297f062015-04-02 00:23:46 +0000963});