blob: 04e188e5c700384e9aacb6847f1bacf6a21d8c42 [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',
11 'buttongroup/menu',
Akrona0ea3c32018-12-14 18:33:48 +010012 'match/attachement',
Akrond8692de2018-07-26 13:06:01 +020013 'hint/foundries/cnx',
14 'hint/foundries/mate'], function (
15 matchClass,
16 tableClass,
17 relClass,
18 panelClass,
19 metaClass,
20 infoClass,
21 matchTreeItemClass,
22 matchRelClass,
Akrona0ea3c32018-12-14 18:33:48 +010023 matchTreeMenuClass,
24 attachementClass) {
Nils Diewald7c8ced22015-04-15 19:21:00 +000025
Akrond8692de2018-07-26 13:06:01 +020026 var available = [
27 'base/s=spans',
28 'corenlp/c=spans',
29 'corenlp/ne=tokens',
30 'corenlp/p=tokens',
31 'corenlp/s=spans',
32 'glemm/l=tokens',
33 'mate/l=tokens',
34 'mate/m=tokens',
35 'mate/p=tokens',
36 'opennlp/p=tokens',
37 'opennlp/s=spans',
38 'tt/l=tokens',
39 'tt/p=tokens',
40 'tt/s=spans'
41 ];
Nils Diewalda297f062015-04-02 00:23:46 +000042
Akrond8692de2018-07-26 13:06:01 +020043 var match = {
44 'corpusID' : 'WPD',
45 'docID' : 'UUU',
46 'textID' : '01912',
47 'matchID' : 'p121-122',
48 'textSigle' : 'WPD/UUU/01912',
49 'available' : available
Nils Diewalda297f062015-04-02 00:23:46 +000050 };
Akrond8692de2018-07-26 13:06:01 +020051
52
53 var fields = [
54 {
55 "@type": "koral:field",
56 "key": "author",
57 "type": "type:text",
58 "value": "Sprachpfleger, u.a."
59 },
60 {
61 "@type": "koral:field",
62 "key": "textClass",
Akrond45a1702018-11-19 18:15:17 +010063 "type": "type:keywords", // May not be necessary
Akrond8692de2018-07-26 13:06:01 +020064 "value": ["kultur", "film"]
65 },
66 {
67 "@type":"koral:field",
68 "key":"foundries",
69 "type":"type:string",
70 "value":[
71 "corenlp",
72 "corenlp\/constituency",
73 "corenlp\/morpho",
74 "corenlp\/sentences",
75 "dereko",
76 "dereko\/structure",
77 "dereko\/structure\/base-sentences-paragraphs-pagebreaks",
78 "opennlp",
79 "opennlp\/morpho",
80 "opennlp\/sentences"
81 ]
Akrona0ea3c32018-12-14 18:33:48 +010082 },
83 {
84 "@type": "koral:field",
85 "key": "xlink",
86 "type": "type:attachement",
87 "value": "data:application/x.korap-link;title=Cool,https://de.wikipedia.org/wiki/Beispiel"
88 },
89
Akrond8692de2018-07-26 13:06:01 +020090 ];
91
92
93 var snippet = "<span title=\"cnx/l:meist\">" +
94 " <span title=\"cnx/p:ADV\">" +
95 " <span title=\"cnx/syn:@PREMOD\">" +
96 " <span title=\"mate/l:meist\">" +
97 " <span title=\"mate/l:meist\">" +
98 " <span title=\"mate/p:ADV\">" +
99 " <span title=\"opennlp/p:ADV\">meist</span>" +
100 " </span>" +
101 " </span>" +
102 " </span>" +
103 " </span>" +
104 " </span>" +
105 "</span>" +
Akronad1e46a2018-09-19 15:55:40 +0200106 "<mark>" +
Akrond8692de2018-07-26 13:06:01 +0200107 "<span title=\"cnx/l:deutlich\">" +
108 " <span title=\"cnx/p:A\">" +
109 " <span title=\"cnx/syn:@PREMOD\">" +
110 " <span title=\"mate/l:deutlich\">" +
111 " <span title=\"mate/m:degree:pos\">" +
112 " <span title=\"mate/p:ADJD\">" +
113 " <span title=\"opennlp/p:ADJD\">deutlich</span>" +
114 " </span>" +
115 " </span>" +
116 " </span>" +
117 " </span>" +
118 " </span>" +
119 "</span>" +
Akronad1e46a2018-09-19 15:55:40 +0200120 "</mark>" +
Akrond8692de2018-07-26 13:06:01 +0200121 "<span title=\"cnx/l:fähig\">" +
122 " <span title=\"cnx/l:leistung\">" +
123 " <span title=\"cnx/p:A\">" +
124 " <span title=\"cnx/p:ADJA\">" +
125 " <span title=\"cnx/syn:@NH\">" +
126 " <span title=\"mate/l:leistungsfähig\">" +
127 " <span title=\"mate/m:degree:comp\">" +
128 " <span title=\"mate/p:ADJD\">" +
129 " <span title=\"opennlp/p:ADJD\">leistungsfähiger</span>" +
130 " </span>" +
131 " </span>" +
132 " </span>" +
133 " </span>" +
134 " </span>" +
135 " </span>" +
136 " </span>" +
137 "</span>";
138
139 var treeSnippet =
140 "<span class=\"context-left\"></span>" +
141 "<span class=\"match\">" +
142 " <span title=\"xip/c:MC\">" +
143 " <span title=\"xip/c:TOP\">" +
144 " <span title=\"xip/c:PP\">" +
145 " <span title=\"xip/c:PREP\">Mit</span>" +
146 " <span title=\"xip/c:NP\">" +
147 " <span title=\"xip/c:DET\">dieser</span>" +
148 " <span title=\"xip/c:NPA\">" +
149 " <span title=\"xip/c:NOUN\">Methode</span>" +
150 " </span>" +
151 " </span>" +
152 " </span>" +
153 " <span title=\"xip/c:VERB\">ist</span>" +
154 " <mark>" +
155 " <span title=\"xip/c:NP\">" +
156 " <span title=\"xip/c:PRON\">es</span>" +
157 " </span>" +
158 " <span title=\"xip/c:AP\">" +
159 " <span title=\"xip/c:ADV\">nun</span>" +
160 " <span title=\"xip/c:ADJ\">möglich</span>" +
161 " </span>" +
162 " </mark>" +
163 " <span title=\"xip/c:ADV\">z. B.</span>" +
164 " <span title=\"xip/c:NPA\">" +
165 " <span title=\"xip/c:NP\">" +
166 " <span title=\"xip/c:NOUN\">Voice</span>" +
167 " </span>" +
168 " </span>" + "(" +
169 " <span title=\"xip/c:INS\">" +
170 " <span title=\"xip/c:NPA\">" +
171 " <span title=\"xip/c:NP\">" +
172 " <span title=\"xip/c:NOUN\">Sprache</span>" +
173 " </span>" +
174 " </span>" +
175 " </span>" + ")" +
176 " <span title=\"xip/c:VERB\">bevorzugt</span>" +
177 " <span title=\"xip/c:PP\">" +
178 " <span title=\"xip/c:PREP\">in</span>" +
179 " <span title=\"xip/c:NP\">" +
180 " <span title=\"xip/c:PRON\">der</span>" +
181 " </span>" +
182 " <span title=\"xip/c:NPA\">" +
183 " <span title=\"xip/c:NP\">" +
184 " <span title=\"xip/c:NOUN\">Bridge</span>" +
185 " </span>" +
186 " </span>" +
187 " </span>" +
188 " <span title=\"xip/c:INFC\">" +
189 " <span title=\"xip/c:INS\">" +
190 " <span title=\"xip/c:VERB\">weiterzugeben</span>" +
191 " </span>" +
192 " </span>" +
193 " </span>" +
194 " </span>" +
195 "</span>" +
196 "<span class=\"context-right\"></span>";
197
198
199 function matchElementFactory () {
200 var me = document.createElement('li');
201
202 me.setAttribute(
203 'data-available-info',
204 'base/s=spans corenlp/c=spans corenlp/ne=tokens corenlp/p=tokens' +
205 ' corenlp/s=spans glemm/l=tokens mate/l=tokens mate/m=tokens' +
206 ' mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens' +
207 ' tt/p=tokens tt/s=spans');
208
209 me.setAttribute('data-corpus-id', 'WPD');
210 me.setAttribute('data-doc-id', 'FFF');
211 me.setAttribute('data-text-id', '01460');
212 me.setAttribute('data-text-sigle', 'WPD/FFF/01460');
213 me.setAttribute('data-match-id', 'p119-120');
214 me.innerHTML = '<div><div class="snippet">check</div></div><p class="ref">me</p>';
215 return me;
216 };
217
218 function matchElementReal () {
219 var me = document.createElement('em');
220 me.innerHTML =
221 '<li data-match-id="p85183-85184"' +
222 ' data-text-sigle="GOE/AGI/00000"' +
223 ' 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"' +
224 ' 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;}"' +
225 ' id="GOE/AGI/00000#p85183-85184">' +
226 '<div>' +
227 '<div class="flag"></div>' +
228 '<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>' +
229 '</div>' +
230 '<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>' +
231 '</li>';
232 return me.firstChild;
233 };
234
235 var beforeAllFunc = function () {
236 // Override getMatchInfo API call
237 KorAP.API.getMatchInfo = function (x, param, cb) {
238 if (param['spans'] === undefined || param['spans'] === false)
239 cb({ "snippet": snippet });
240 else
241 cb({ "snippet": treeSnippet });
242 };
243 };
244
245 var afterAllFunc = function () {
246 KorAP.API.getMatchInfo = undefined;
247 // KorAP.annotationHelper = undefined;
248 var body = document.body;
249 for (var i in body.children) {
250 if (body.children[i].nodeType && body.children[i].nodeType === 1) {
251 if (!body.children[i].classList.contains("jasmine_html-reporter")) {
252 body.removeChild(body.children[i]);
253 };
254 };
255 };
256 };
257
Akron671fdb92017-09-12 18:09:46 +0200258
Nils Diewald7c8ced22015-04-15 19:21:00 +0000259 describe('KorAP.InfoLayer', function () {
Akrond8692de2018-07-26 13:06:01 +0200260 beforeAll(beforeAllFunc);
261 afterAll(afterAllFunc);
Nils Diewalda297f062015-04-02 00:23:46 +0000262
Nils Diewald7c8ced22015-04-15 19:21:00 +0000263 it('should be initializable', function () {
264 expect(
Akron671fdb92017-09-12 18:09:46 +0200265 function() { infoClass.create() }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000266 ).toThrow(new Error("Missing parameters"));
Nils Diewalda297f062015-04-02 00:23:46 +0000267
Nils Diewald7c8ced22015-04-15 19:21:00 +0000268 expect(
Akron671fdb92017-09-12 18:09:46 +0200269 function() { infoClass.create("base") }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000270 ).toThrow(new Error("Missing parameters"));
Nils Diewalda297f062015-04-02 00:23:46 +0000271
Nils Diewald7c8ced22015-04-15 19:21:00 +0000272 var layer = infoClass.create("base", "s");
273 expect(layer).toBeTruthy();
274 expect(layer.foundry).toEqual("base");
275 expect(layer.layer).toEqual("s");
276 expect(layer.type).toEqual("tokens");
Nils Diewalda297f062015-04-02 00:23:46 +0000277
Nils Diewald7c8ced22015-04-15 19:21:00 +0000278 layer = infoClass.create("cnx", "syn", "spans");
279 expect(layer).toBeTruthy();
280 expect(layer.foundry).toEqual("cnx");
281 expect(layer.layer).toEqual("syn");
282 expect(layer.type).toEqual("spans");
Nils Diewald58141332015-04-07 16:18:45 +0000283 });
284 });
Nils Diewalda297f062015-04-02 00:23:46 +0000285
Nils Diewalda297f062015-04-02 00:23:46 +0000286
Nils Diewald7c8ced22015-04-15 19:21:00 +0000287 describe('KorAP.Match', function () {
Akrond8692de2018-07-26 13:06:01 +0200288 beforeAll(beforeAllFunc);
289 afterAll(afterAllFunc);
290
Nils Diewald7c8ced22015-04-15 19:21:00 +0000291 var match = {
292 'corpusID' : 'WPD',
293 'docID' : 'UUU',
294 'textID' : '01912',
295 'matchID' : 'p121-122',
Akron0a6768f2016-07-13 18:00:43 +0200296 'textSigle' : 'WPD/UUU/01912',
Nils Diewald7c8ced22015-04-15 19:21:00 +0000297 'available' : available
298 };
299
Nils Diewald7c8ced22015-04-15 19:21:00 +0000300 it('should be initializable by Object', function () {
301 expect(function() {
Akron671fdb92017-09-12 18:09:46 +0200302 matchClass.create()
Nils Diewald7c8ced22015-04-15 19:21:00 +0000303 }).toThrow(new Error('Missing parameters'));
304
305 expect(matchClass.create(match)).toBeTruthy();
306
307 var m = matchClass.create(match);
Akron0a6768f2016-07-13 18:00:43 +0200308 expect(m.textSigle).toEqual("WPD/UUU/01912");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000309 expect(m.matchID).toEqual("p121-122");
310
311 // /corpus/WPD/UUU.01912/p121-122/matchInfo?spans=false&foundry=*
312 var m = matchClass.create(match);
313
314 // Spans:
315 var spans = m.getSpans();
316 expect(spans[0].foundry).toEqual("base");
317 expect(spans[0].layer).toEqual("s");
318
319 expect(spans[1].foundry).toEqual("corenlp");
320 expect(spans[1].layer).toEqual("c");
321
322 expect(spans[2].foundry).toEqual("corenlp");
323 expect(spans[2].layer).toEqual("s");
324
325 expect(spans[spans.length-1].foundry).toEqual("tt");
326 expect(spans[spans.length-1].layer).toEqual("s");
327
328 // Tokens:
329 var tokens = m.getTokens();
330 expect(tokens[0].foundry).toEqual("corenlp");
331 expect(tokens[0].layer).toEqual("ne");
332
333 expect(tokens[1].foundry).toEqual("corenlp");
334 expect(tokens[1].layer).toEqual("p");
335
336 expect(tokens[tokens.length-1].foundry).toEqual("tt");
337 expect(tokens[tokens.length-1].layer).toEqual("p");
Nils Diewald58141332015-04-07 16:18:45 +0000338 });
Nils Diewalda297f062015-04-02 00:23:46 +0000339
340
Akroncdb0baa2016-11-07 01:52:11 +0100341 it('should be initializable by Node 1', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000342 var m = matchClass.create(matchElementFactory());
Akron0a6768f2016-07-13 18:00:43 +0200343 expect(m.textSigle).toEqual("WPD/FFF/01460");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000344 expect(m.matchID).toEqual("p119-120");
Nils Diewalda297f062015-04-02 00:23:46 +0000345
Nils Diewald7c8ced22015-04-15 19:21:00 +0000346 // Spans:
347 var spans = m.getSpans();
348 expect(spans[0].foundry).toEqual("base");
349 expect(spans[0].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000350
Nils Diewald7c8ced22015-04-15 19:21:00 +0000351 expect(spans[1].foundry).toEqual("corenlp");
352 expect(spans[1].layer).toEqual("c");
Nils Diewalda297f062015-04-02 00:23:46 +0000353
Nils Diewald7c8ced22015-04-15 19:21:00 +0000354 expect(spans[2].foundry).toEqual("corenlp");
355 expect(spans[2].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000356
Nils Diewald7c8ced22015-04-15 19:21:00 +0000357 expect(spans[spans.length-1].foundry).toEqual("tt");
358 expect(spans[spans.length-1].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000359
Nils Diewald7c8ced22015-04-15 19:21:00 +0000360 // Tokens:
361 var tokens = m.getTokens();
362 expect(tokens[0].foundry).toEqual("corenlp");
363 expect(tokens[0].layer).toEqual("ne");
Nils Diewalda297f062015-04-02 00:23:46 +0000364
Nils Diewald7c8ced22015-04-15 19:21:00 +0000365 expect(tokens[1].foundry).toEqual("corenlp");
366 expect(tokens[1].layer).toEqual("p");
Nils Diewalda297f062015-04-02 00:23:46 +0000367
Nils Diewald7c8ced22015-04-15 19:21:00 +0000368 expect(tokens[tokens.length-1].foundry).toEqual("tt");
369 expect(tokens[tokens.length-1].layer).toEqual("p");
Nils Diewalda297f062015-04-02 00:23:46 +0000370
Nils Diewald7c8ced22015-04-15 19:21:00 +0000371 });
Nils Diewalda297f062015-04-02 00:23:46 +0000372
Akroncdb0baa2016-11-07 01:52:11 +0100373 it('should be initializable by Node 2', function () {
374 var ele = matchElementReal();
375 var m = matchClass.create(ele);
376 expect(m.textSigle).toEqual("GOE/AGI/00000");
377 expect(m.matchID).toEqual("p85183-85184");
378 });
379
380
Nils Diewald7c8ced22015-04-15 19:21:00 +0000381 it('should react to gui actions', function () {
382 var e = matchElementFactory();
Nils Diewalda297f062015-04-02 00:23:46 +0000383
Nils Diewald7c8ced22015-04-15 19:21:00 +0000384 expect(e.classList.contains('active')).toBe(false);
385 expect(e["_match"]).toBe(undefined);
Nils Diewalda297f062015-04-02 00:23:46 +0000386
Nils Diewald7c8ced22015-04-15 19:21:00 +0000387 var m = matchClass.create(e);
388
389 expect(e.classList.contains('active')).toBe(false);
390 expect(e["_match"]).not.toBe(undefined);
391
392 // Open the match
393 m.open();
394
395 expect(e.classList.contains('active')).toBe(true);
396 expect(e["_match"]).not.toBe(undefined);
397
Akronbfe912c2018-07-17 19:30:52 +0200398 actions = e.querySelector("p.ref > div.action.button-group").children;
Akrond141a362018-07-10 18:12:13 +0200399
Akronbfe912c2018-07-17 19:30:52 +0200400 expect(actions[0].getAttribute("class")).toEqual("metatable");
Akronc296ca22018-04-24 16:35:26 +0200401 expect(actions[1].getAttribute("class")).toEqual("info");
402 expect(actions[2].getAttribute("class")).toEqual("tree");
403
Nils Diewald7c8ced22015-04-15 19:21:00 +0000404 // Close the match
Akronec6bb8e2018-08-29 13:07:56 +0200405 m.minimize();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000406 expect(e.classList.contains('active')).toBe(false);
407 expect(e["_match"]).not.toBe(undefined);
Nils Diewald58141332015-04-07 16:18:45 +0000408 });
Nils Diewalda297f062015-04-02 00:23:46 +0000409
Akrond8692de2018-07-26 13:06:01 +0200410 it('should open tree menu', function () {
Akronc296ca22018-04-24 16:35:26 +0200411 var e = matchElementFactory();
412 var m = matchClass.create(e);
413 m.open();
Akronbfe912c2018-07-17 19:30:52 +0200414 var relation = e.querySelector("p.ref > div.action.button-group > span:nth-of-type(3)");
Akronc296ca22018-04-24 16:35:26 +0200415 expect(relation.getAttribute("class")).toEqual("tree");
Akron52ed22d2018-07-11 17:05:19 +0200416 expect(document.getElementsByClassName("button-group-list").length).toEqual(0);
Akronc296ca22018-04-24 16:35:26 +0200417
418 expect(document.activeElement.tagName).toEqual("BODY");
419
420 // Show menu
421 relation.click();
Akron52ed22d2018-07-11 17:05:19 +0200422 expect(document.getElementsByClassName("button-group-list").length).toEqual(1);
Akronc296ca22018-04-24 16:35:26 +0200423
424 expect(document.activeElement.tagName).toEqual("UL");
425
426 // Choose first tree
Akron52ed22d2018-07-11 17:05:19 +0200427 document.getElementsByClassName("button-group-list")[0].getElementsByTagName("li")[1].click();
Akronc296ca22018-04-24 16:35:26 +0200428 expect(e.querySelector("div.matchinfo div.matchtree h6 span").innerText).toEqual("corenlp");
429
430 // This should blur the focus
431 expect(document.activeElement.tagName).toEqual("BODY");
432 });
433
434 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000435
Akron7f9a6a32018-07-18 15:05:23 +0200436 describe('KorAP.TableView', function () {
Akrond8692de2018-07-26 13:06:01 +0200437 beforeAll(beforeAllFunc);
438 afterAll(afterAllFunc);
439
Akron7f9a6a32018-07-18 15:05:23 +0200440 var table;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000441
Akron7f9a6a32018-07-18 15:05:23 +0200442 var matchObj = matchClass.create(match);
443 var tableObj = tableClass.create(matchObj);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000444
445 var table1, table2;
446
Nils Diewald7c8ced22015-04-15 19:21:00 +0000447 it('should fail to load a table async', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200448 expect(tableObj).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000449
Akron7f9a6a32018-07-18 15:05:23 +0200450 tableObj.getData([], function (tablen) {
Akron671fdb92017-09-12 18:09:46 +0200451 table1 = tablen;
452 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000453 });
454 });
455
Akron671fdb92017-09-12 18:09:46 +0200456
Akronaeeb8252018-09-19 18:51:00 +0200457 xit('should\'nt be parsable (async)', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000458 expect(table1).not.toBeTruthy();
459 });
460
Nils Diewald7c8ced22015-04-15 19:21:00 +0000461
Nils Diewald7c8ced22015-04-15 19:21:00 +0000462 it('should be retrieved async', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200463 expect(tableObj).toBeTruthy();
464 tableObj.getData(undefined, function (x) {
Akron671fdb92017-09-12 18:09:46 +0200465 table = x;
466 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000467 });
468 });
Nils Diewalda297f062015-04-02 00:23:46 +0000469
Akron7f9a6a32018-07-18 15:05:23 +0200470 it('should parse into a table (async)', function () {
471 expect(table).toBeTruthy();
Akron5b1a6af2018-02-05 15:41:16 +0100472
Akron7f9a6a32018-07-18 15:05:23 +0200473 expect(table.length()).toBe(3);
474
475 expect(table.getToken(0)).toBe("meist");
476 expect(table.getToken(1)).toBe("deutlich");
477 expect(table.getToken(2)).toBe("leistungsfähiger");
478
479 expect(table.getValue(0, "cnx", "p")[0]).toBe("ADV");
480 expect(table.getValue(0, "cnx", "syn")[0]).toBe("@PREMOD");
481 expect(table.getValue(0, "mate", "l")[0]).toBe("meist");
482 expect(table.getValue(0, "mate", "l")[1]).toBeUndefined();
483
484 expect(table.getValue(2, "cnx", "l")[0]).toBe("fähig");
485 expect(table.getValue(2, "cnx", "l")[1]).toBe("leistung");
486 });
487
488 it('should be rendered async', function () {
Akron5b1a6af2018-02-05 15:41:16 +0100489 var e = table.element().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000490 expect(e.nodeName).toBe('TABLE');
491 expect(e.children[0].nodeName).toBe('THEAD');
492 var tr = e.children[0].children[0];
493 expect(tr.nodeName).toBe('TR');
494 expect(tr.children[0].nodeName).toBe('TH');
Nils Diewald58141332015-04-07 16:18:45 +0000495
Nils Diewald7c8ced22015-04-15 19:21:00 +0000496 expect(tr.children[0].firstChild.nodeValue).toBe('Foundry');
497 expect(tr.children[1].firstChild.nodeValue).toBe('Layer');
498 expect(tr.children[2].firstChild.nodeValue).toBe('meist');
Akronad1e46a2018-09-19 15:55:40 +0200499 expect(tr.children[2].classList.contains('mark')).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000500 expect(tr.children[3].firstChild.nodeValue).toBe('deutlich');
Akronad1e46a2018-09-19 15:55:40 +0200501 expect(tr.children[3].classList.contains('mark')).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000502 expect(tr.children[4].firstChild.nodeValue).toBe('leistungsfähiger');
Akronad1e46a2018-09-19 15:55:40 +0200503 expect(tr.children[4].classList.contains('mark')).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000504
505 // first row
506 tr = e.children[1].children[0];
507 expect(tr.nodeName).toBe('TR');
508 expect(tr.getAttribute('tabindex')).toEqual('0');
509 expect(tr.children[0].nodeName).toBe('TH');
510 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
511 expect(tr.children[1].firstChild.nodeValue).toEqual('l');
512 expect(tr.children[2].firstChild.nodeValue).toEqual('meist');
513 expect(tr.children[3].firstChild.nodeValue).toEqual('deutlich');
Akron47774c42017-07-03 20:14:55 +0200514 expect(tr.children[4].firstChild.firstChild.nodeValue).toEqual('fähig');
515 expect(tr.children[4].lastChild.firstChild.nodeValue).toEqual('leistung');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000516
517 // second row
518 tr = e.children[1].children[1];
519 expect(tr.nodeName).toBe('TR');
520 expect(tr.getAttribute('tabindex')).toEqual('0');
521 expect(tr.children[0].nodeName).toBe('TH');
522 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
523 expect(tr.children[1].firstChild.nodeValue).toEqual('p');
524 expect(tr.children[2].firstChild.nodeValue).toEqual('ADV');
525 expect(tr.children[3].firstChild.nodeValue).toEqual('A');
Akron47774c42017-07-03 20:14:55 +0200526 expect(tr.children[4].firstChild.firstChild.nodeValue).toEqual('A');
527 expect(tr.children[4].lastChild.firstChild.nodeValue).toEqual('ADJA');
Akronf2279c42017-12-21 13:48:46 +0100528
529 expect(tr.children[4].firstChild.getAttribute("title")).toEqual('Adjective');
530 expect(tr.children[2].getAttribute("title")).toEqual('Adverb');
531
Nils Diewald58141332015-04-07 16:18:45 +0000532 });
Akron7f9a6a32018-07-18 15:05:23 +0200533
534
535 it('should parse into a table view (sync)', function () {
536 var matchElement = matchElementFactory();
537 expect(matchElement.tagName).toEqual('LI');
538
539 // Match
540 expect(matchElement.children[0].tagName).toEqual('DIV');
541
542 // snippet
543 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
544 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
545 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
546
547 // reference
548 expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
549 expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
550
551 // not yet
552 expect(matchElement.children[0].children[1]).toBe(undefined);
553
554 /*
555 var info = matchClass.create(matchElement).info();
556 info.showTable();
557 */
558 var matchObj = matchClass.create(matchElement);
559 matchObj.open();
560
561 // Match
562 expect(matchElement.children[0].tagName).toEqual('DIV');
563
564 // snippet
565 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
566
567 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
568
569 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
570
571 // reference
572
573 expect(matchElement.children[2].classList.contains('ref')).toBeTruthy();
574 expect(matchElement.children[2].childNodes[1].nodeValue).toEqual('me');
575
576 // Add table
577 matchObj.panel.addTable();
578
579 // now
580 var infotable = matchElement.children[1];
581 expect(infotable.tagName).toEqual('DIV');
582
583 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
584
585 expect(infotable.firstChild.firstChild.firstChild.classList.contains('matchtable')).toBeTruthy();
586
587 // expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
588 });
589
Nils Diewald58141332015-04-07 16:18:45 +0000590 });
Nils Diewalda297f062015-04-02 00:23:46 +0000591
Akron7f9a6a32018-07-18 15:05:23 +0200592 describe('KorAP.RelationsView', function () {
Akrond8692de2018-07-26 13:06:01 +0200593 beforeAll(beforeAllFunc);
594 afterAll(afterAllFunc);
595
Nils Diewald7c8ced22015-04-15 19:21:00 +0000596 var tree;
Nils Diewalda297f062015-04-02 00:23:46 +0000597
Nils Diewald7c8ced22015-04-15 19:21:00 +0000598 it('should be rendered async 1', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200599 var matchObj = matchClass.create(match);
600 var relObj = relClass.create(matchObj);
601 expect(relObj).toBeTruthy();
602 relObj.getData(undefined, undefined, "spans", function (y) {
Akron671fdb92017-09-12 18:09:46 +0200603 tree = y;
604 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000605 });
606 });
Nils Diewalda297f062015-04-02 00:23:46 +0000607
Nils Diewald7c8ced22015-04-15 19:21:00 +0000608 it('should be rendered async 2', function () {
Akron7f9a6a32018-07-18 15:05:23 +0200609 expect(tree).toBeTruthy();
610 expect(tree.nodes()).toEqual(49);
611
Nils Diewald7c8ced22015-04-15 19:21:00 +0000612 var e = tree.element();
613 expect(e.nodeName).toEqual('svg');
614 expect(e.getElementsByTagName('g').length).toEqual(48);
Nils Diewald58141332015-04-07 16:18:45 +0000615 });
Akron7f9a6a32018-07-18 15:05:23 +0200616
617
618 it('should add a tree view async 2', function () {
619 var matchElement = matchElementFactory();
620 var matchObj = matchClass.create(matchElement);
621 matchObj.open();
622 matchObj.panel.addTree('mate', 'beebop', 'spans', function () {
623 done();
624 });
625
626 // With added tree
627 var tree = matchElement.children[1].firstChild.firstChild.firstChild;
628 expect(tree.tagName).toEqual('DIV');
629 expect(tree.classList.contains('matchtree')).toBeTruthy();
630 expect(tree.children[0].tagName).toEqual('H6');
631 expect(tree.children[0].children[0].tagName).toEqual('SPAN');
632 expect(tree.children[0].children[0].firstChild.nodeValue).toEqual('mate');
633 expect(tree.children[0].children[1].tagName).toEqual('SPAN');
634 expect(tree.children[0].children[1].firstChild.nodeValue).toEqual('beebop');
635
636 expect(tree.children[1].tagName).toEqual('DIV');
637 });
638
Nils Diewald58141332015-04-07 16:18:45 +0000639 });
Nils Diewalda297f062015-04-02 00:23:46 +0000640
Nils Diewald7c8ced22015-04-15 19:21:00 +0000641
642 describe('KorAP.MatchTreeItem', function () {
Akrond8692de2018-07-26 13:06:01 +0200643 beforeAll(beforeAllFunc);
644 afterAll(afterAllFunc);
645
Nils Diewald7c8ced22015-04-15 19:21:00 +0000646 it('should be initializable', function () {
647 var mi = matchTreeItemClass.create(['cnx/c', 'cnx', 'c'])
648 expect(mi.element().firstChild.nodeValue).toEqual('cnx/c');
649 expect(mi.lcField()).toEqual(' cnx/c');
650 expect(mi.foundry()).toEqual('cnx');
651 expect(mi.layer()).toEqual('c');
652 });
Nils Diewalda297f062015-04-02 00:23:46 +0000653 });
Nils Diewalda297f062015-04-02 00:23:46 +0000654
655
Akron671fdb92017-09-12 18:09:46 +0200656 describe('KorAP.MatchRelation', function () {
Akrond8692de2018-07-26 13:06:01 +0200657 beforeAll(beforeAllFunc);
658 afterAll(afterAllFunc);
Akron671fdb92017-09-12 18:09:46 +0200659
660 var relExample = "<span class=\"context-left\"></span>" +
661 "<span class=\"match\">" +
662 " <span xml:id=\"token-GOE/AGA/01784-p199\">" +
663 " <span xlink:title=\"malt/d:ADV\" " +
664 " xlink:type=\"simple\" " +
665 " xlink:href=\"#token-GOE/AGA/01784-p199\">dann</span>" +
666 " </span>" +
667 " zog " +
668 " <span xlink:title=\"malt/d:SUBJ\" " +
669 " xlink:type=\"simple\" " +
670 " xlink:href=\"#token-GOE/AGA/01784-p199\">ich</span>" +
671 " <span xml:id=\"token-GOE/AGA/01784-p202\">" +
672 " <span xlink:title=\"malt/d:OBJA\" " +
673 " xlink:type=\"simple\" " +
674 " xlink:href=\"#token-GOE/AGA/01784-p199\">mich</span>" +
675 " </span>" +
676 "</span>" +
677 "<span class=\"context-right\"></span>";
678
679
680 it('should be initializable', function () {
Akrond8692de2018-07-26 13:06:01 +0200681 var tree = matchRelClass.create();
Akron671fdb92017-09-12 18:09:46 +0200682 expect(tree.size()).toBe(0);
683 });
684
685 it('should be parse string data', function () {
Akrond8692de2018-07-26 13:06:01 +0200686 var tree = matchRelClass.create(relExample);
Akron671fdb92017-09-12 18:09:46 +0200687 expect(tree.size()).toBe(4);
688 });
Akron671fdb92017-09-12 18:09:46 +0200689 });
690
691
Nils Diewald7c8ced22015-04-15 19:21:00 +0000692 describe('KorAP.MatchTreeMenu', function () {
Akrond8692de2018-07-26 13:06:01 +0200693 beforeAll(beforeAllFunc);
694 afterAll(afterAllFunc);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000695
696 it('should be initializable', function () {
Akrond8692de2018-07-26 13:06:01 +0200697 var menu = matchTreeMenuClass.create([
Akron671fdb92017-09-12 18:09:46 +0200698 ['cnx/c', 'cnx', 'c'],
699 ['xip/c', 'xip', 'c']
Akrond8692de2018-07-26 13:06:01 +0200700 ], matchTreeItemClass);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000701
Akrond8692de2018-07-26 13:06:01 +0200702 expect(menu.itemClass()).toEqual(matchTreeItemClass);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000703 expect(menu.element().nodeName).toEqual('UL');
Akronaba7a5a2016-08-15 21:58:33 +0200704 expect(menu.element().classList.contains('visible')).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000705 expect(menu.limit()).toEqual(6);
706 menu.show();
Akronaba7a5a2016-08-15 21:58:33 +0200707 expect(menu.element().classList.contains('visible')).toBeTruthy();
Akronc1457bf2015-06-11 19:24:00 +0200708 expect(menu.item(0).active()).toBe(false);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000709 });
Nils Diewalda297f062015-04-02 00:23:46 +0000710 });
hebasta999d6c12018-04-23 12:44:59 +0200711
712 //Test display and sorting of meta information
713 describe('KorAP.Meta', function(){
Akrond8692de2018-07-26 13:06:01 +0200714 beforeAll(beforeAllFunc);
715 afterAll(afterAllFunc);
716
717 var met = metaClass.create(match, fields);
hebasta999d6c12018-04-23 12:44:59 +0200718 var mel = met.element();
719
720 // Meta information should be parsed into a list
721 it('should parse in a meta view', function(){
Akronfa32c9d2018-11-20 15:39:18 +0100722 expect(mel.tagName).toEqual('DL');
723 expect(mel.children[0].tagName).toEqual('DIV');
724 expect(mel.children[0].children[0].tagName).toEqual('DT');
725 expect(mel.children[0].children[0].attributes[0].name).toEqual('title');
726 expect(mel.children[0].children[1].tagName).toEqual('DD');
727 expect(mel.children[0].children[1].getAttribute('data-type')).toEqual('type:text')
hebasta999d6c12018-04-23 12:44:59 +0200728
Akronfa32c9d2018-11-20 15:39:18 +0100729 expect(mel.children[0].children[0].firstChild.nodeValue).toEqual('author');
730 expect(mel.children[0].children[1].firstChild.nodeValue).toEqual('Sprachpfleger, u.a.');
731 expect(mel.children[0].children[0].attributes[0].value).toEqual('author');
hebasta999d6c12018-04-23 12:44:59 +0200732 });
733
734
Akronfa32c9d2018-11-20 15:39:18 +0100735 /* The keywords in the meta information list should be formatted to be able
736 to chose each keyword separately in the corpusByMatch assistant. */
737 it('keywords should be formatted', function(){
hebasta999d6c12018-04-23 12:44:59 +0200738
Akronfa32c9d2018-11-20 15:39:18 +0100739 //type:string or type:keyword should b not relevant
740 expect(mel.children[1].children[1].getAttribute('data-type')).toEqual('type:string')
741 expect(mel.children[1].children[1].classList.contains('metakeyvalues')).toBeTruthy;
742 expect(mel.children[1].children[1].children[0].tagName).toEqual('DIV');
743 expect(mel.children[1].children[1].children[0].firstChild.nodeValue).toEqual('corenlp');
744 expect(mel.children[1].children[1].children[1].tagName).toEqual('DIV');
745 expect(mel.children[1].children[1].children[1].firstChild.nodeValue).toEqual('corenlp\/constituency');
746
747 expect(mel.children[2].children[1].classList.contains('metakeyvalues')).toBeTruthy;
748 expect(mel.children[2].children[1].children[0].tagName).toEqual('DIV');
749 expect(mel.children[2].children[1].children[0].firstChild.nodeValue).toEqual('kultur');
750 expect(mel.children[2].children[1].children[1].tagName).toEqual('DIV');
751 expect(mel.children[2].children[1].children[1].firstChild.nodeValue).toEqual('film');
hebasta999d6c12018-04-23 12:44:59 +0200752 });
Akrona0ea3c32018-12-14 18:33:48 +0100753
754 it('attachements should be formatted', function(){
755 //type:attachement
756 expect(mel.children[3].children[1].getAttribute('data-type')).toEqual('type:attachement')
757 expect(mel.children[3].children[1].classList.contains('metakeyvalues')).toBeFalsy;
758 expect(mel.children[3].children[0].firstChild.nodeValue).toEqual('xlink');
759 expect(mel.children[3].children[1].firstChild.textContent).toEqual('Cool');
760 expect(mel.children[3].children[1].firstChild.tagName).toEqual('A');
761 expect(mel.children[3].children[1].firstChild.getAttribute('href')).toEqual('https://de.wikipedia.org/wiki/Beispiel');
762 });
763
764
hebasta999d6c12018-04-23 12:44:59 +0200765
Akronfa32c9d2018-11-20 15:39:18 +0100766 // Meta information should be sorted alphabetically
767 it('should be alphabetically sorted', function(){
768 var a = mel.children[0].children[0].firstChild.nodeValue;
769 var b = mel.children[1].children[0].firstChild.nodeValue;
770 var c = mel.children[2].children[0].firstChild.nodeValue;
771 expect(a.localeCompare(b)).toBe(-1);
772 expect(b.localeCompare(c)).toBe(-1);
Akrona0ea3c32018-12-14 18:33:48 +0100773 });
774
775
776 it('should handle attachements', function () {
777 let uri = attachementClass.create("data:text/plain;title=new,Hallo");
778 expect(uri.contentType).toEqual("text/plain");
779
780 expect(uri.payload).toEqual("Hallo");
781 expect(uri.base64).toBeFalsy();
782 expect(uri.isLink).toBeFalsy();
783 expect(uri.param["title"]).toEqual("new");
784
785 uri = attachementClass.create("data:application/x.korap-link,https://de.wikipedia.org/wiki/Beispiel");
786 expect(uri.contentType).toEqual("application/x.korap-link");
787 expect(uri.payload).toEqual("https://de.wikipedia.org/wiki/Beispiel");
788 expect(uri.base64).toBeFalsy();
789 expect(uri.isLink).toBeTruthy();
790 expect(uri.inline().textContent).toEqual("https://de.wikipedia.org/wiki/Beispiel");
791 expect(uri.inline().nodeType).toEqual(1);
792 expect(uri.inline().tagName).toEqual("A");
793 expect(uri.inline().getAttribute("rel")).toEqual("noopener noreferrer");
794
795
796 uri = attachementClass.create("data:application/x.korap-link;title=Das ist ein Titel,https://de.wikipedia.org/wiki/Beispiel");
797 expect(uri.contentType).toEqual("application/x.korap-link");
798 expect(uri.payload).toEqual("https://de.wikipedia.org/wiki/Beispiel");
799 expect(uri.base64).toBeFalsy();
800 expect(uri.isLink).toBeTruthy();
801 expect(uri.inline().textContent).toEqual("Das ist ein Titel");
802 expect(uri.inline().nodeType).toEqual(1);
803 expect(uri.inline().tagName).toEqual("A");
804 expect(uri.inline().getAttribute("rel")).toEqual("noopener noreferrer");
805
806
807 uri = attachementClass.create("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D");
808 expect(uri.contentType).toEqual("text/plain");
809 expect(uri.payload).toEqual("Hello, World!");
810 expect(uri.base64).toBeTruthy();
811 expect(uri.isLink).toBeFalsy();
812 expect(uri.inline().nodeType).toEqual(3);
813 expect(uri.inline().textContent).toEqual("Hello, World!");
814
815 uri = attachementClass.create("data:text/plain;title= new ; subTitle = old ;base64,SGVsbG8sIFdvcmxkIQ%3D%3D");
816 expect(uri.contentType).toEqual("text/plain");
817 expect(uri.payload).toEqual("Hello, World!");
818 expect(uri.param["title"]).toEqual("new");
819 expect(uri.param["subTitle"]).toEqual("old");
820 expect(uri.base64).toBeTruthy();
821 expect(uri.isLink).toBeFalsy();
822 expect(uri.inline().nodeType).toEqual(3);
823 expect(uri.inline().textContent).toEqual("Hello, World!");
824 });
hebasta999d6c12018-04-23 12:44:59 +0200825 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000826 // table = view.toTable();
827 // table.sortBy('');
828 // table.element();
829 // tree = view.toTree();
830 // tree.element();
Nils Diewalda297f062015-04-02 00:23:46 +0000831});