blob: 6166138ba3330f6a340f921727689689fee922dc [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 });
Akrone57e8802020-10-17 08:23:45 +0200454
455 it('should toggle', function () {
456 var e = matchElementFactory();
457
458 expect(e.classList.contains('active')).toBe(false);
459 expect(e["_match"]).toBe(undefined);
460
461 var m = matchClass.create(e);
462
463 expect(e.classList.contains('active')).toBe(false);
464 expect(e["_match"]).not.toBe(undefined);
465
466 // Open the match
467 m.open();
468
469 expect(e.classList.contains('active')).toBe(true);
470 expect(e["_match"]).not.toBe(undefined);
471
472 m.toggle();
473
474 expect(e.classList.contains('active')).toBe(false);
475 expect(e["_match"]).not.toBe(undefined);
476
477 m.toggle();
478
479 expect(e.classList.contains('active')).toBe(true);
480 expect(e["_match"]).not.toBe(undefined);
481 });
482
Akrond8692de2018-07-26 13:06:01 +0200483 it('should open tree menu', function () {
Akronc296ca22018-04-24 16:35:26 +0200484 var e = matchElementFactory();
485 var m = matchClass.create(e);
486 m.open();
Akronbfe912c2018-07-17 19:30:52 +0200487 var relation = e.querySelector("p.ref > div.action.button-group > span:nth-of-type(3)");
Akronc296ca22018-04-24 16:35:26 +0200488 expect(relation.getAttribute("class")).toEqual("tree");
Akron52ed22d2018-07-11 17:05:19 +0200489 expect(document.getElementsByClassName("button-group-list").length).toEqual(0);
Akronc296ca22018-04-24 16:35:26 +0200490 expect(document.activeElement.tagName).toEqual("BODY");
hebasta87f1b1f2019-07-30 13:03:23 +0200491
Akronc296ca22018-04-24 16:35:26 +0200492 // Show menu
493 relation.click();
Akron52ed22d2018-07-11 17:05:19 +0200494 expect(document.getElementsByClassName("button-group-list").length).toEqual(1);
Akronc296ca22018-04-24 16:35:26 +0200495 expect(document.activeElement.tagName).toEqual("UL");
hebasta87f1b1f2019-07-30 13:03:23 +0200496
Akronc296ca22018-04-24 16:35:26 +0200497 // Choose first tree
Akron52ed22d2018-07-11 17:05:19 +0200498 document.getElementsByClassName("button-group-list")[0].getElementsByTagName("li")[1].click();
Akronc296ca22018-04-24 16:35:26 +0200499 expect(e.querySelector("div.matchinfo div.matchtree h6 span").innerText).toEqual("corenlp");
500
501 // This should blur the focus
502 expect(document.activeElement.tagName).toEqual("BODY");
hebasta87f1b1f2019-07-30 13:03:23 +0200503
Akronc296ca22018-04-24 16:35:26 +0200504 });
505
506 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000507
Akron7f9a6a32018-07-18 15:05:23 +0200508 describe('KorAP.TableView', function () {
Akrond8692de2018-07-26 13:06:01 +0200509 beforeAll(beforeAllFunc);
510 afterAll(afterAllFunc);
Akron5dc31172019-05-15 18:43:48 +0200511
512 let longString = " und robust sind auch die anderen Traktoren, die hier der Übersicht wegen keine Erwähnung finden können.";
513
Akron7f9a6a32018-07-18 15:05:23 +0200514 var table;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000515
Akron7f9a6a32018-07-18 15:05:23 +0200516 var matchObj = matchClass.create(match);
517 var tableObj = tableClass.create(matchObj);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000518
519 var table1, table2;
520
Nils Diewald7c8ced22015-04-15 19:21:00 +0000521 it('should fail to load a table async', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200522 expect(tableObj).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000523
Akron7f9a6a32018-07-18 15:05:23 +0200524 tableObj.getData([], function (tablen) {
Akron671fdb92017-09-12 18:09:46 +0200525 table1 = tablen;
526 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000527 });
528 });
529
Akron671fdb92017-09-12 18:09:46 +0200530
Akronaeeb8252018-09-19 18:51:00 +0200531 xit('should\'nt be parsable (async)', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000532 expect(table1).not.toBeTruthy();
533 });
534
Nils Diewald7c8ced22015-04-15 19:21:00 +0000535
Nils Diewald7c8ced22015-04-15 19:21:00 +0000536 it('should be retrieved async', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200537 expect(tableObj).toBeTruthy();
538 tableObj.getData(undefined, function (x) {
Akron671fdb92017-09-12 18:09:46 +0200539 table = x;
540 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000541 });
542 });
Nils Diewalda297f062015-04-02 00:23:46 +0000543
Akron7f9a6a32018-07-18 15:05:23 +0200544 it('should parse into a table (async)', function () {
545 expect(table).toBeTruthy();
Akron5b1a6af2018-02-05 15:41:16 +0100546
Akron158fce12019-12-17 14:43:29 +0100547 expect(table.length()).toBe(8);
Akron7f9a6a32018-07-18 15:05:23 +0200548
Akron1a780fe2019-05-21 15:59:00 +0200549 expect(table.getToken(0)).toBe("");
550 expect(table.getToken(1)).toBe("Außerdem ");
551 expect(table.getToken(2)).toBe("meist");
552 expect(table.getToken(3)).toBe("deutlich");
Akron158fce12019-12-17 14:43:29 +0100553 expect(table.getToken(5)).toBe("leistungsfähiger");
554 expect(table.getToken(6)).toBe(longString);
Akron7f9a6a32018-07-18 15:05:23 +0200555
Akron1a780fe2019-05-21 15:59:00 +0200556 expect(table.getValue(2, "cnx", "p")[0]).toBe("ADV");
557 expect(table.getValue(2, "cnx", "syn")[0]).toBe("@PREMOD");
558 expect(table.getValue(2, "mate", "l")[0]).toBe("meist");
559 expect(table.getValue(2, "mate", "l")[1]).toBeUndefined();
Akron7f9a6a32018-07-18 15:05:23 +0200560
Akron158fce12019-12-17 14:43:29 +0100561 expect(table.getValue(5, "cnx", "l")[0]).toBe("fähig");
562 expect(table.getValue(5, "cnx", "l")[1]).toBe("leistung");
Akron7f9a6a32018-07-18 15:05:23 +0200563 });
564
565 it('should be rendered async', function () {
Akron5b1a6af2018-02-05 15:41:16 +0100566 var e = table.element().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000567 expect(e.nodeName).toBe('TABLE');
568 expect(e.children[0].nodeName).toBe('THEAD');
569 var tr = e.children[0].children[0];
570 expect(tr.nodeName).toBe('TR');
571 expect(tr.children[0].nodeName).toBe('TH');
Nils Diewald58141332015-04-07 16:18:45 +0000572
Nils Diewald7c8ced22015-04-15 19:21:00 +0000573 expect(tr.children[0].firstChild.nodeValue).toBe('Foundry');
574 expect(tr.children[1].firstChild.nodeValue).toBe('Layer');
Akron1a780fe2019-05-21 15:59:00 +0200575
576 expect(tr.children[2].classList.contains('cutted')).toBeTruthy();
577 expect(tr.children[3].firstChild.nodeValue).toBe('Außerdem ');
578
579
580 expect(tr.children[4].firstChild.nodeValue).toBe('meist');
Akronad1e46a2018-09-19 15:55:40 +0200581 expect(tr.children[4].classList.contains('mark')).toBeFalsy();
Akron1a780fe2019-05-21 15:59:00 +0200582 expect(tr.children[5].firstChild.nodeValue).toBe('deutlich');
583 expect(tr.children[5].classList.contains('mark')).toBeTruthy();
Akron158fce12019-12-17 14:43:29 +0100584 expect(tr.children[6].firstChild.nodeValue).toBe('▮');
585 expect(tr.children[7].firstChild.nodeValue).toBe('leistungsfähiger');
586 expect(tr.children[7].classList.contains('mark')).toBeFalsy();
587 expect(tr.children[7].hasAttribute("title")).toBeFalsy();
588 expect(tr.children[8].firstChild.nodeValue).toBe(longString);
589 expect(tr.children[8].getAttribute("title")).toBe(longString);
590 expect(tr.children[9].classList.contains('cutted')).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000591
592 // first row
593 tr = e.children[1].children[0];
594 expect(tr.nodeName).toBe('TR');
595 expect(tr.getAttribute('tabindex')).toEqual('0');
596 expect(tr.children[0].nodeName).toBe('TH');
597 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
598 expect(tr.children[1].firstChild.nodeValue).toEqual('l');
Akron1a780fe2019-05-21 15:59:00 +0200599 expect(tr.children[4].firstChild.nodeValue).toEqual('meist');
600 expect(tr.children[5].firstChild.nodeValue).toEqual('deutlich');
Akron158fce12019-12-17 14:43:29 +0100601 expect(tr.children[6].firstChild).toBeNull();
602 expect(tr.children[7].firstChild.firstChild.nodeValue).toEqual('fähig');
603 expect(tr.children[7].lastChild.firstChild.nodeValue).toEqual('leistung');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000604
605 // second row
606 tr = e.children[1].children[1];
607 expect(tr.nodeName).toBe('TR');
608 expect(tr.getAttribute('tabindex')).toEqual('0');
609 expect(tr.children[0].nodeName).toBe('TH');
610 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
611 expect(tr.children[1].firstChild.nodeValue).toEqual('p');
Akron1a780fe2019-05-21 15:59:00 +0200612 expect(tr.children[4].firstChild.nodeValue).toEqual('ADV');
613 expect(tr.children[5].firstChild.nodeValue).toEqual('A');
Akron158fce12019-12-17 14:43:29 +0100614 expect(tr.children[6].firstChild).toBeNull();
615 expect(tr.children[7].firstChild.firstChild.nodeValue).toEqual('A');
616 expect(tr.children[7].lastChild.firstChild.nodeValue).toEqual('ADJA');
Akronf2279c42017-12-21 13:48:46 +0100617
Akron158fce12019-12-17 14:43:29 +0100618 expect(tr.children[7].firstChild.getAttribute("title")).toEqual('Adjective');
Akron1a780fe2019-05-21 15:59:00 +0200619 expect(tr.children[4].getAttribute("title")).toEqual('Adverb');
Nils Diewald58141332015-04-07 16:18:45 +0000620 });
Akron7f9a6a32018-07-18 15:05:23 +0200621
622
623 it('should parse into a table view (sync)', function () {
624 var matchElement = matchElementFactory();
625 expect(matchElement.tagName).toEqual('LI');
626
627 // Match
628 expect(matchElement.children[0].tagName).toEqual('DIV');
629
630 // snippet
631 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
632 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
633 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
634
635 // reference
636 expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
637 expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
638
639 // not yet
640 expect(matchElement.children[0].children[1]).toBe(undefined);
641
642 /*
643 var info = matchClass.create(matchElement).info();
644 info.showTable();
645 */
646 var matchObj = matchClass.create(matchElement);
647 matchObj.open();
648
649 // Match
650 expect(matchElement.children[0].tagName).toEqual('DIV');
651
652 // snippet
653 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
654
655 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
656
657 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
658
659 // reference
660
661 expect(matchElement.children[2].classList.contains('ref')).toBeTruthy();
662 expect(matchElement.children[2].childNodes[1].nodeValue).toEqual('me');
663
664 // Add table
665 matchObj.panel.addTable();
666
667 // now
668 var infotable = matchElement.children[1];
669 expect(infotable.tagName).toEqual('DIV');
670
671 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
672
673 expect(infotable.firstChild.firstChild.firstChild.classList.contains('matchtable')).toBeTruthy();
674
675 // expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
676 });
677
Akron158fce12019-12-17 14:43:29 +0100678 it('should parse into a table view with non-verbal elements (sync)', function () {
679 var matchElement = matchElementFactory();
680 expect(matchElement.tagName).toEqual('LI');
681 });
682
Nils Diewald58141332015-04-07 16:18:45 +0000683 });
Nils Diewalda297f062015-04-02 00:23:46 +0000684
Akron7f9a6a32018-07-18 15:05:23 +0200685 describe('KorAP.RelationsView', function () {
Akrond8692de2018-07-26 13:06:01 +0200686 beforeAll(beforeAllFunc);
687 afterAll(afterAllFunc);
688
Nils Diewald7c8ced22015-04-15 19:21:00 +0000689 var tree;
Nils Diewalda297f062015-04-02 00:23:46 +0000690
Nils Diewald7c8ced22015-04-15 19:21:00 +0000691 it('should be rendered async 1', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200692 var matchObj = matchClass.create(match);
693 var relObj = relClass.create(matchObj);
694 expect(relObj).toBeTruthy();
695 relObj.getData(undefined, undefined, "spans", function (y) {
Akron671fdb92017-09-12 18:09:46 +0200696 tree = y;
697 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000698 });
699 });
Nils Diewalda297f062015-04-02 00:23:46 +0000700
Nils Diewald7c8ced22015-04-15 19:21:00 +0000701 it('should be rendered async 2', function () {
Akron7f9a6a32018-07-18 15:05:23 +0200702 expect(tree).toBeTruthy();
703 expect(tree.nodes()).toEqual(49);
704
Nils Diewald7c8ced22015-04-15 19:21:00 +0000705 var e = tree.element();
706 expect(e.nodeName).toEqual('svg');
707 expect(e.getElementsByTagName('g').length).toEqual(48);
Nils Diewald58141332015-04-07 16:18:45 +0000708 });
Akron7f9a6a32018-07-18 15:05:23 +0200709
710
711 it('should add a tree view async 2', function () {
712 var matchElement = matchElementFactory();
713 var matchObj = matchClass.create(matchElement);
714 matchObj.open();
715 matchObj.panel.addTree('mate', 'beebop', 'spans', function () {
716 done();
717 });
718
719 // With added tree
720 var tree = matchElement.children[1].firstChild.firstChild.firstChild;
721 expect(tree.tagName).toEqual('DIV');
722 expect(tree.classList.contains('matchtree')).toBeTruthy();
723 expect(tree.children[0].tagName).toEqual('H6');
724 expect(tree.children[0].children[0].tagName).toEqual('SPAN');
725 expect(tree.children[0].children[0].firstChild.nodeValue).toEqual('mate');
726 expect(tree.children[0].children[1].tagName).toEqual('SPAN');
727 expect(tree.children[0].children[1].firstChild.nodeValue).toEqual('beebop');
728
729 expect(tree.children[1].tagName).toEqual('DIV');
730 });
731
Akron3bdac532019-03-04 13:24:43 +0100732 it('should make the tree downloadable', function () {
733 var treeClass = matchHierClass.create(treeSnippetHierarchy);
734 var treeElement = treeClass.element();
735 expect(treeElement.tagName).toEqual("svg");
736
737 var base64 = treeClass.toBase64();
738 var str = atob(base64);
739 expect(str).toMatch(new RegExp('<defs><style>path'));
740 expect(str).not.toMatch(new RegExp('&nbsp;'));
741 expect(str).toMatch(new RegExp('&amp;'));
742 });
Nils Diewald58141332015-04-07 16:18:45 +0000743 });
Nils Diewalda297f062015-04-02 00:23:46 +0000744
Nils Diewald7c8ced22015-04-15 19:21:00 +0000745
746 describe('KorAP.MatchTreeItem', function () {
Akrond8692de2018-07-26 13:06:01 +0200747 beforeAll(beforeAllFunc);
748 afterAll(afterAllFunc);
749
Nils Diewald7c8ced22015-04-15 19:21:00 +0000750 it('should be initializable', function () {
751 var mi = matchTreeItemClass.create(['cnx/c', 'cnx', 'c'])
752 expect(mi.element().firstChild.nodeValue).toEqual('cnx/c');
753 expect(mi.lcField()).toEqual(' cnx/c');
754 expect(mi.foundry()).toEqual('cnx');
755 expect(mi.layer()).toEqual('c');
756 });
Nils Diewalda297f062015-04-02 00:23:46 +0000757 });
Nils Diewalda297f062015-04-02 00:23:46 +0000758
759
Akron671fdb92017-09-12 18:09:46 +0200760 describe('KorAP.MatchRelation', function () {
Akrond8692de2018-07-26 13:06:01 +0200761 beforeAll(beforeAllFunc);
762 afterAll(afterAllFunc);
Akron671fdb92017-09-12 18:09:46 +0200763
764 var relExample = "<span class=\"context-left\"></span>" +
765 "<span class=\"match\">" +
766 " <span xml:id=\"token-GOE/AGA/01784-p199\">" +
767 " <span xlink:title=\"malt/d:ADV\" " +
768 " xlink:type=\"simple\" " +
769 " xlink:href=\"#token-GOE/AGA/01784-p199\">dann</span>" +
770 " </span>" +
771 " zog " +
772 " <span xlink:title=\"malt/d:SUBJ\" " +
773 " xlink:type=\"simple\" " +
774 " xlink:href=\"#token-GOE/AGA/01784-p199\">ich</span>" +
775 " <span xml:id=\"token-GOE/AGA/01784-p202\">" +
776 " <span xlink:title=\"malt/d:OBJA\" " +
777 " xlink:type=\"simple\" " +
778 " xlink:href=\"#token-GOE/AGA/01784-p199\">mich</span>" +
779 " </span>" +
780 "</span>" +
781 "<span class=\"context-right\"></span>";
782
783
784 it('should be initializable', function () {
Akrond8692de2018-07-26 13:06:01 +0200785 var tree = matchRelClass.create();
Akron671fdb92017-09-12 18:09:46 +0200786 expect(tree.size()).toBe(0);
787 });
788
789 it('should be parse string data', function () {
Akrond8692de2018-07-26 13:06:01 +0200790 var tree = matchRelClass.create(relExample);
Akron671fdb92017-09-12 18:09:46 +0200791 expect(tree.size()).toBe(4);
792 });
Akron0a785d42020-10-12 17:21:46 +0200793
794 it('should accept missing data', function () {
795 var relExample2 = "<span class=\"context-left\"><\/span>"+
796 "<span class=\"match\">"+
797 "{{"+
798 "<span xml:id=\"token-WUD17\/D95\/09441-p180\">"+
799 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p179\">Wikiläum<\/span>"+
800 "<\/span>"+
801 "|"+
802 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p180\">Silber<\/span>"+
803 "|"+
804 "<span xlink:title=\"malt\/d:DET\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p183\">Dein<\/span>"+
805 " "+
806 "<span xml:id=\"token-WUD17\/D95\/09441-p183\">"+
807 "<span xlink:title=\"malt\/d:ROOT\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p179-196\">Freund<\/span>"+
808 "<\/span>"+
809 " "+
810 "<span xlink:title=\"malt\/d:DET\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p185\">der<\/span>"+
811 " "+
812 "<span xml:id=\"token-WUD17\/D95\/09441-p185-186\">"+
813 "<span xml:id=\"token-WUD17\/D95\/09441-p185\">"+
814 "<mark>"+
815 "<span xlink:title=\"malt\/d:GMOD\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p183\">Baum<\/span>"+
816 "<\/mark>"+
817 "<\/span>"+
818 "| "+
819 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p185-186\">09:38<\/span>"+
820 "<\/span>"+
821 ", "+
822 "<span xlink:title=\"malt\/d:ATTR\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p188\">22.<\/span>"+
823 " "+
824 "<span xml:id=\"token-WUD17\/D95\/09441-p188\">"+
825 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p183\">Aug.<\/span>"+
826 "<\/span>"+
827 " "+
828 "<span xml:id=\"token-WUD17\/D95\/09441-p189\">"+
829 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p188\">2015<\/span>"+
830 "<\/span>"+
831 " ("+
832 "<span xlink:title=\"malt\/d:PAR\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p189\">CEST<\/span>"+
833 ")"+
834 "<\/span>"+
835 "<span class=\"context-right\"><\/span>";
836 var tree = matchRelClass.create(relExample2);
837 expect(tree.size()).toBe(18);
838 var treeElement = tree.element();
839 expect(treeElement.tagName).toEqual("svg");
840 tree.show();
841 expect(treeElement.querySelector("text[text-anchor=\"middle\"]").textContent).toEqual("APP");
842 });
Akron671fdb92017-09-12 18:09:46 +0200843 });
844
845
Nils Diewald7c8ced22015-04-15 19:21:00 +0000846 describe('KorAP.MatchTreeMenu', function () {
Akrond8692de2018-07-26 13:06:01 +0200847 beforeAll(beforeAllFunc);
848 afterAll(afterAllFunc);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000849
850 it('should be initializable', function () {
Akrond8692de2018-07-26 13:06:01 +0200851 var menu = matchTreeMenuClass.create([
Akron671fdb92017-09-12 18:09:46 +0200852 ['cnx/c', 'cnx', 'c'],
853 ['xip/c', 'xip', 'c']
Akrond8692de2018-07-26 13:06:01 +0200854 ], matchTreeItemClass);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000855
Akrond8692de2018-07-26 13:06:01 +0200856 expect(menu.itemClass()).toEqual(matchTreeItemClass);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000857 expect(menu.element().nodeName).toEqual('UL');
Akronaba7a5a2016-08-15 21:58:33 +0200858 expect(menu.element().classList.contains('visible')).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000859 expect(menu.limit()).toEqual(6);
860 menu.show();
Akronaba7a5a2016-08-15 21:58:33 +0200861 expect(menu.element().classList.contains('visible')).toBeTruthy();
Akronc1457bf2015-06-11 19:24:00 +0200862 expect(menu.item(0).active()).toBe(false);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000863 });
Nils Diewalda297f062015-04-02 00:23:46 +0000864 });
hebasta999d6c12018-04-23 12:44:59 +0200865
866 //Test display and sorting of meta information
867 describe('KorAP.Meta', function(){
Akrond8692de2018-07-26 13:06:01 +0200868 beforeAll(beforeAllFunc);
869 afterAll(afterAllFunc);
870
871 var met = metaClass.create(match, fields);
hebasta999d6c12018-04-23 12:44:59 +0200872 var mel = met.element();
873
874 // Meta information should be parsed into a list
875 it('should parse in a meta view', function(){
Akronfa32c9d2018-11-20 15:39:18 +0100876 expect(mel.tagName).toEqual('DL');
877 expect(mel.children[0].tagName).toEqual('DIV');
878 expect(mel.children[0].children[0].tagName).toEqual('DT');
879 expect(mel.children[0].children[0].attributes[0].name).toEqual('title');
880 expect(mel.children[0].children[1].tagName).toEqual('DD');
881 expect(mel.children[0].children[1].getAttribute('data-type')).toEqual('type:text')
hebasta999d6c12018-04-23 12:44:59 +0200882
Akronfa32c9d2018-11-20 15:39:18 +0100883 expect(mel.children[0].children[0].firstChild.nodeValue).toEqual('author');
884 expect(mel.children[0].children[1].firstChild.nodeValue).toEqual('Sprachpfleger, u.a.');
885 expect(mel.children[0].children[0].attributes[0].value).toEqual('author');
hebasta999d6c12018-04-23 12:44:59 +0200886 });
887
888
Akronfa32c9d2018-11-20 15:39:18 +0100889 /* The keywords in the meta information list should be formatted to be able
890 to chose each keyword separately in the corpusByMatch assistant. */
891 it('keywords should be formatted', function(){
hebasta999d6c12018-04-23 12:44:59 +0200892
Akronfa32c9d2018-11-20 15:39:18 +0100893 //type:string or type:keyword should b not relevant
894 expect(mel.children[1].children[1].getAttribute('data-type')).toEqual('type:string')
895 expect(mel.children[1].children[1].classList.contains('metakeyvalues')).toBeTruthy;
896 expect(mel.children[1].children[1].children[0].tagName).toEqual('DIV');
897 expect(mel.children[1].children[1].children[0].firstChild.nodeValue).toEqual('corenlp');
898 expect(mel.children[1].children[1].children[1].tagName).toEqual('DIV');
899 expect(mel.children[1].children[1].children[1].firstChild.nodeValue).toEqual('corenlp\/constituency');
900
901 expect(mel.children[2].children[1].classList.contains('metakeyvalues')).toBeTruthy;
902 expect(mel.children[2].children[1].children[0].tagName).toEqual('DIV');
903 expect(mel.children[2].children[1].children[0].firstChild.nodeValue).toEqual('kultur');
904 expect(mel.children[2].children[1].children[1].tagName).toEqual('DIV');
905 expect(mel.children[2].children[1].children[1].firstChild.nodeValue).toEqual('film');
hebasta999d6c12018-04-23 12:44:59 +0200906 });
Akrona0ea3c32018-12-14 18:33:48 +0100907
908 it('attachements should be formatted', function(){
Akrond3bb85b2019-02-08 10:15:13 +0100909 //type:attachement with a link
Akrona0ea3c32018-12-14 18:33:48 +0100910 expect(mel.children[3].children[1].getAttribute('data-type')).toEqual('type:attachement')
911 expect(mel.children[3].children[1].classList.contains('metakeyvalues')).toBeFalsy;
912 expect(mel.children[3].children[0].firstChild.nodeValue).toEqual('xlink');
913 expect(mel.children[3].children[1].firstChild.textContent).toEqual('Cool');
914 expect(mel.children[3].children[1].firstChild.tagName).toEqual('A');
915 expect(mel.children[3].children[1].firstChild.getAttribute('href')).toEqual('https://de.wikipedia.org/wiki/Beispiel');
Akrond3bb85b2019-02-08 10:15:13 +0100916
917 //type:attachement with plain text
918 expect(mel.children[4].children[1].getAttribute('data-type')).toEqual('type:attachement')
919 expect(mel.children[4].children[1].classList.contains('metakeyvalues')).toBeFalsy;
920 expect(mel.children[4].children[0].firstChild.nodeValue).toEqual('z-reference');
921 expect(mel.children[4].children[1].firstChild.nodeValue).toEqual('This is a reference');
922 });
Akrona0ea3c32018-12-14 18:33:48 +0100923
924
hebasta999d6c12018-04-23 12:44:59 +0200925
Akronfa32c9d2018-11-20 15:39:18 +0100926 // Meta information should be sorted alphabetically
927 it('should be alphabetically sorted', function(){
928 var a = mel.children[0].children[0].firstChild.nodeValue;
929 var b = mel.children[1].children[0].firstChild.nodeValue;
930 var c = mel.children[2].children[0].firstChild.nodeValue;
931 expect(a.localeCompare(b)).toBe(-1);
932 expect(b.localeCompare(c)).toBe(-1);
Akrona0ea3c32018-12-14 18:33:48 +0100933 });
934
935
936 it('should handle attachements', function () {
937 let uri = attachementClass.create("data:text/plain;title=new,Hallo");
938 expect(uri.contentType).toEqual("text/plain");
939
940 expect(uri.payload).toEqual("Hallo");
941 expect(uri.base64).toBeFalsy();
942 expect(uri.isLink).toBeFalsy();
943 expect(uri.param["title"]).toEqual("new");
944
945 uri = attachementClass.create("data:application/x.korap-link,https://de.wikipedia.org/wiki/Beispiel");
946 expect(uri.contentType).toEqual("application/x.korap-link");
947 expect(uri.payload).toEqual("https://de.wikipedia.org/wiki/Beispiel");
948 expect(uri.base64).toBeFalsy();
949 expect(uri.isLink).toBeTruthy();
950 expect(uri.inline().textContent).toEqual("https://de.wikipedia.org/wiki/Beispiel");
951 expect(uri.inline().nodeType).toEqual(1);
952 expect(uri.inline().tagName).toEqual("A");
953 expect(uri.inline().getAttribute("rel")).toEqual("noopener noreferrer");
954
955
956 uri = attachementClass.create("data:application/x.korap-link;title=Das ist ein Titel,https://de.wikipedia.org/wiki/Beispiel");
957 expect(uri.contentType).toEqual("application/x.korap-link");
958 expect(uri.payload).toEqual("https://de.wikipedia.org/wiki/Beispiel");
959 expect(uri.base64).toBeFalsy();
960 expect(uri.isLink).toBeTruthy();
961 expect(uri.inline().textContent).toEqual("Das ist ein Titel");
962 expect(uri.inline().nodeType).toEqual(1);
963 expect(uri.inline().tagName).toEqual("A");
964 expect(uri.inline().getAttribute("rel")).toEqual("noopener noreferrer");
965
966
967 uri = attachementClass.create("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D");
968 expect(uri.contentType).toEqual("text/plain");
969 expect(uri.payload).toEqual("Hello, World!");
970 expect(uri.base64).toBeTruthy();
971 expect(uri.isLink).toBeFalsy();
972 expect(uri.inline().nodeType).toEqual(3);
973 expect(uri.inline().textContent).toEqual("Hello, World!");
974
975 uri = attachementClass.create("data:text/plain;title= new ; subTitle = old ;base64,SGVsbG8sIFdvcmxkIQ%3D%3D");
976 expect(uri.contentType).toEqual("text/plain");
977 expect(uri.payload).toEqual("Hello, World!");
978 expect(uri.param["title"]).toEqual("new");
979 expect(uri.param["subTitle"]).toEqual("old");
980 expect(uri.base64).toBeTruthy();
981 expect(uri.isLink).toBeFalsy();
982 expect(uri.inline().nodeType).toEqual(3);
983 expect(uri.inline().textContent).toEqual("Hello, World!");
984 });
hebasta999d6c12018-04-23 12:44:59 +0200985 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000986 // table = view.toTable();
987 // table.sortBy('');
988 // table.element();
989 // tree = view.toTree();
990 // tree.element();
Nils Diewalda297f062015-04-02 00:23:46 +0000991});