blob: 79133ee4b436650bb979ce7f0e7f0681351c1a35 [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 });
Akron671fdb92017-09-12 18:09:46 +0200765 });
766
767
Nils Diewald7c8ced22015-04-15 19:21:00 +0000768 describe('KorAP.MatchTreeMenu', function () {
Akrond8692de2018-07-26 13:06:01 +0200769 beforeAll(beforeAllFunc);
770 afterAll(afterAllFunc);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000771
772 it('should be initializable', function () {
Akrond8692de2018-07-26 13:06:01 +0200773 var menu = matchTreeMenuClass.create([
Akron671fdb92017-09-12 18:09:46 +0200774 ['cnx/c', 'cnx', 'c'],
775 ['xip/c', 'xip', 'c']
Akrond8692de2018-07-26 13:06:01 +0200776 ], matchTreeItemClass);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000777
Akrond8692de2018-07-26 13:06:01 +0200778 expect(menu.itemClass()).toEqual(matchTreeItemClass);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000779 expect(menu.element().nodeName).toEqual('UL');
Akronaba7a5a2016-08-15 21:58:33 +0200780 expect(menu.element().classList.contains('visible')).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000781 expect(menu.limit()).toEqual(6);
782 menu.show();
Akronaba7a5a2016-08-15 21:58:33 +0200783 expect(menu.element().classList.contains('visible')).toBeTruthy();
Akronc1457bf2015-06-11 19:24:00 +0200784 expect(menu.item(0).active()).toBe(false);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000785 });
Nils Diewalda297f062015-04-02 00:23:46 +0000786 });
hebasta999d6c12018-04-23 12:44:59 +0200787
788 //Test display and sorting of meta information
789 describe('KorAP.Meta', function(){
Akrond8692de2018-07-26 13:06:01 +0200790 beforeAll(beforeAllFunc);
791 afterAll(afterAllFunc);
792
793 var met = metaClass.create(match, fields);
hebasta999d6c12018-04-23 12:44:59 +0200794 var mel = met.element();
795
796 // Meta information should be parsed into a list
797 it('should parse in a meta view', function(){
Akronfa32c9d2018-11-20 15:39:18 +0100798 expect(mel.tagName).toEqual('DL');
799 expect(mel.children[0].tagName).toEqual('DIV');
800 expect(mel.children[0].children[0].tagName).toEqual('DT');
801 expect(mel.children[0].children[0].attributes[0].name).toEqual('title');
802 expect(mel.children[0].children[1].tagName).toEqual('DD');
803 expect(mel.children[0].children[1].getAttribute('data-type')).toEqual('type:text')
hebasta999d6c12018-04-23 12:44:59 +0200804
Akronfa32c9d2018-11-20 15:39:18 +0100805 expect(mel.children[0].children[0].firstChild.nodeValue).toEqual('author');
806 expect(mel.children[0].children[1].firstChild.nodeValue).toEqual('Sprachpfleger, u.a.');
807 expect(mel.children[0].children[0].attributes[0].value).toEqual('author');
hebasta999d6c12018-04-23 12:44:59 +0200808 });
809
810
Akronfa32c9d2018-11-20 15:39:18 +0100811 /* The keywords in the meta information list should be formatted to be able
812 to chose each keyword separately in the corpusByMatch assistant. */
813 it('keywords should be formatted', function(){
hebasta999d6c12018-04-23 12:44:59 +0200814
Akronfa32c9d2018-11-20 15:39:18 +0100815 //type:string or type:keyword should b not relevant
816 expect(mel.children[1].children[1].getAttribute('data-type')).toEqual('type:string')
817 expect(mel.children[1].children[1].classList.contains('metakeyvalues')).toBeTruthy;
818 expect(mel.children[1].children[1].children[0].tagName).toEqual('DIV');
819 expect(mel.children[1].children[1].children[0].firstChild.nodeValue).toEqual('corenlp');
820 expect(mel.children[1].children[1].children[1].tagName).toEqual('DIV');
821 expect(mel.children[1].children[1].children[1].firstChild.nodeValue).toEqual('corenlp\/constituency');
822
823 expect(mel.children[2].children[1].classList.contains('metakeyvalues')).toBeTruthy;
824 expect(mel.children[2].children[1].children[0].tagName).toEqual('DIV');
825 expect(mel.children[2].children[1].children[0].firstChild.nodeValue).toEqual('kultur');
826 expect(mel.children[2].children[1].children[1].tagName).toEqual('DIV');
827 expect(mel.children[2].children[1].children[1].firstChild.nodeValue).toEqual('film');
hebasta999d6c12018-04-23 12:44:59 +0200828 });
Akrona0ea3c32018-12-14 18:33:48 +0100829
830 it('attachements should be formatted', function(){
Akrond3bb85b2019-02-08 10:15:13 +0100831 //type:attachement with a link
Akrona0ea3c32018-12-14 18:33:48 +0100832 expect(mel.children[3].children[1].getAttribute('data-type')).toEqual('type:attachement')
833 expect(mel.children[3].children[1].classList.contains('metakeyvalues')).toBeFalsy;
834 expect(mel.children[3].children[0].firstChild.nodeValue).toEqual('xlink');
835 expect(mel.children[3].children[1].firstChild.textContent).toEqual('Cool');
836 expect(mel.children[3].children[1].firstChild.tagName).toEqual('A');
837 expect(mel.children[3].children[1].firstChild.getAttribute('href')).toEqual('https://de.wikipedia.org/wiki/Beispiel');
Akrond3bb85b2019-02-08 10:15:13 +0100838
839 //type:attachement with plain text
840 expect(mel.children[4].children[1].getAttribute('data-type')).toEqual('type:attachement')
841 expect(mel.children[4].children[1].classList.contains('metakeyvalues')).toBeFalsy;
842 expect(mel.children[4].children[0].firstChild.nodeValue).toEqual('z-reference');
843 expect(mel.children[4].children[1].firstChild.nodeValue).toEqual('This is a reference');
844 });
Akrona0ea3c32018-12-14 18:33:48 +0100845
846
hebasta999d6c12018-04-23 12:44:59 +0200847
Akronfa32c9d2018-11-20 15:39:18 +0100848 // Meta information should be sorted alphabetically
849 it('should be alphabetically sorted', function(){
850 var a = mel.children[0].children[0].firstChild.nodeValue;
851 var b = mel.children[1].children[0].firstChild.nodeValue;
852 var c = mel.children[2].children[0].firstChild.nodeValue;
853 expect(a.localeCompare(b)).toBe(-1);
854 expect(b.localeCompare(c)).toBe(-1);
Akrona0ea3c32018-12-14 18:33:48 +0100855 });
856
857
858 it('should handle attachements', function () {
859 let uri = attachementClass.create("data:text/plain;title=new,Hallo");
860 expect(uri.contentType).toEqual("text/plain");
861
862 expect(uri.payload).toEqual("Hallo");
863 expect(uri.base64).toBeFalsy();
864 expect(uri.isLink).toBeFalsy();
865 expect(uri.param["title"]).toEqual("new");
866
867 uri = attachementClass.create("data:application/x.korap-link,https://de.wikipedia.org/wiki/Beispiel");
868 expect(uri.contentType).toEqual("application/x.korap-link");
869 expect(uri.payload).toEqual("https://de.wikipedia.org/wiki/Beispiel");
870 expect(uri.base64).toBeFalsy();
871 expect(uri.isLink).toBeTruthy();
872 expect(uri.inline().textContent).toEqual("https://de.wikipedia.org/wiki/Beispiel");
873 expect(uri.inline().nodeType).toEqual(1);
874 expect(uri.inline().tagName).toEqual("A");
875 expect(uri.inline().getAttribute("rel")).toEqual("noopener noreferrer");
876
877
878 uri = attachementClass.create("data:application/x.korap-link;title=Das ist ein Titel,https://de.wikipedia.org/wiki/Beispiel");
879 expect(uri.contentType).toEqual("application/x.korap-link");
880 expect(uri.payload).toEqual("https://de.wikipedia.org/wiki/Beispiel");
881 expect(uri.base64).toBeFalsy();
882 expect(uri.isLink).toBeTruthy();
883 expect(uri.inline().textContent).toEqual("Das ist ein Titel");
884 expect(uri.inline().nodeType).toEqual(1);
885 expect(uri.inline().tagName).toEqual("A");
886 expect(uri.inline().getAttribute("rel")).toEqual("noopener noreferrer");
887
888
889 uri = attachementClass.create("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D");
890 expect(uri.contentType).toEqual("text/plain");
891 expect(uri.payload).toEqual("Hello, World!");
892 expect(uri.base64).toBeTruthy();
893 expect(uri.isLink).toBeFalsy();
894 expect(uri.inline().nodeType).toEqual(3);
895 expect(uri.inline().textContent).toEqual("Hello, World!");
896
897 uri = attachementClass.create("data:text/plain;title= new ; subTitle = old ;base64,SGVsbG8sIFdvcmxkIQ%3D%3D");
898 expect(uri.contentType).toEqual("text/plain");
899 expect(uri.payload).toEqual("Hello, World!");
900 expect(uri.param["title"]).toEqual("new");
901 expect(uri.param["subTitle"]).toEqual("old");
902 expect(uri.base64).toBeTruthy();
903 expect(uri.isLink).toBeFalsy();
904 expect(uri.inline().nodeType).toEqual(3);
905 expect(uri.inline().textContent).toEqual("Hello, World!");
906 });
hebasta999d6c12018-04-23 12:44:59 +0200907 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000908 // table = view.toTable();
909 // table.sortBy('');
910 // table.element();
911 // tree = view.toTree();
912 // tree.element();
Nils Diewalda297f062015-04-02 00:23:46 +0000913});