blob: 9b3ef9e19580ff6f779f201e9180ca00e7fa94e0 [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 },
Akrond3bb85b2019-02-08 10:15:13 +010089 {
90 "@type": "koral:field",
91 "key": "z-reference",
92 "type": "type:attachement",
93 "value": "data:,This is a reference"
94 }
Akrond8692de2018-07-26 13:06:01 +020095 ];
96
97
98 var snippet = "<span title=\"cnx/l:meist\">" +
99 " <span title=\"cnx/p:ADV\">" +
100 " <span title=\"cnx/syn:@PREMOD\">" +
101 " <span title=\"mate/l:meist\">" +
102 " <span title=\"mate/l:meist\">" +
103 " <span title=\"mate/p:ADV\">" +
104 " <span title=\"opennlp/p:ADV\">meist</span>" +
105 " </span>" +
106 " </span>" +
107 " </span>" +
108 " </span>" +
109 " </span>" +
110 "</span>" +
Akronad1e46a2018-09-19 15:55:40 +0200111 "<mark>" +
Akrond8692de2018-07-26 13:06:01 +0200112 "<span title=\"cnx/l:deutlich\">" +
113 " <span title=\"cnx/p:A\">" +
114 " <span title=\"cnx/syn:@PREMOD\">" +
115 " <span title=\"mate/l:deutlich\">" +
116 " <span title=\"mate/m:degree:pos\">" +
117 " <span title=\"mate/p:ADJD\">" +
118 " <span title=\"opennlp/p:ADJD\">deutlich</span>" +
119 " </span>" +
120 " </span>" +
121 " </span>" +
122 " </span>" +
123 " </span>" +
124 "</span>" +
Akronad1e46a2018-09-19 15:55:40 +0200125 "</mark>" +
Akrond8692de2018-07-26 13:06:01 +0200126 "<span title=\"cnx/l:fähig\">" +
127 " <span title=\"cnx/l:leistung\">" +
128 " <span title=\"cnx/p:A\">" +
129 " <span title=\"cnx/p:ADJA\">" +
130 " <span title=\"cnx/syn:@NH\">" +
131 " <span title=\"mate/l:leistungsfähig\">" +
132 " <span title=\"mate/m:degree:comp\">" +
133 " <span title=\"mate/p:ADJD\">" +
134 " <span title=\"opennlp/p:ADJD\">leistungsfähiger</span>" +
135 " </span>" +
136 " </span>" +
137 " </span>" +
138 " </span>" +
139 " </span>" +
140 " </span>" +
141 " </span>" +
142 "</span>";
143
144 var treeSnippet =
145 "<span class=\"context-left\"></span>" +
146 "<span class=\"match\">" +
147 " <span title=\"xip/c:MC\">" +
148 " <span title=\"xip/c:TOP\">" +
149 " <span title=\"xip/c:PP\">" +
150 " <span title=\"xip/c:PREP\">Mit</span>" +
151 " <span title=\"xip/c:NP\">" +
152 " <span title=\"xip/c:DET\">dieser</span>" +
153 " <span title=\"xip/c:NPA\">" +
154 " <span title=\"xip/c:NOUN\">Methode</span>" +
155 " </span>" +
156 " </span>" +
157 " </span>" +
158 " <span title=\"xip/c:VERB\">ist</span>" +
159 " <mark>" +
160 " <span title=\"xip/c:NP\">" +
161 " <span title=\"xip/c:PRON\">es</span>" +
162 " </span>" +
163 " <span title=\"xip/c:AP\">" +
164 " <span title=\"xip/c:ADV\">nun</span>" +
165 " <span title=\"xip/c:ADJ\">möglich</span>" +
166 " </span>" +
167 " </mark>" +
168 " <span title=\"xip/c:ADV\">z. B.</span>" +
169 " <span title=\"xip/c:NPA\">" +
170 " <span title=\"xip/c:NP\">" +
171 " <span title=\"xip/c:NOUN\">Voice</span>" +
172 " </span>" +
173 " </span>" + "(" +
174 " <span title=\"xip/c:INS\">" +
175 " <span title=\"xip/c:NPA\">" +
176 " <span title=\"xip/c:NP\">" +
177 " <span title=\"xip/c:NOUN\">Sprache</span>" +
178 " </span>" +
179 " </span>" +
180 " </span>" + ")" +
181 " <span title=\"xip/c:VERB\">bevorzugt</span>" +
182 " <span title=\"xip/c:PP\">" +
183 " <span title=\"xip/c:PREP\">in</span>" +
184 " <span title=\"xip/c:NP\">" +
185 " <span title=\"xip/c:PRON\">der</span>" +
186 " </span>" +
187 " <span title=\"xip/c:NPA\">" +
188 " <span title=\"xip/c:NP\">" +
189 " <span title=\"xip/c:NOUN\">Bridge</span>" +
190 " </span>" +
191 " </span>" +
192 " </span>" +
193 " <span title=\"xip/c:INFC\">" +
194 " <span title=\"xip/c:INS\">" +
195 " <span title=\"xip/c:VERB\">weiterzugeben</span>" +
196 " </span>" +
197 " </span>" +
198 " </span>" +
199 " </span>" +
200 "</span>" +
201 "<span class=\"context-right\"></span>";
202
203
204 function matchElementFactory () {
205 var me = document.createElement('li');
206
207 me.setAttribute(
208 'data-available-info',
209 'base/s=spans corenlp/c=spans corenlp/ne=tokens corenlp/p=tokens' +
210 ' corenlp/s=spans glemm/l=tokens mate/l=tokens mate/m=tokens' +
211 ' mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens' +
212 ' tt/p=tokens tt/s=spans');
213
214 me.setAttribute('data-corpus-id', 'WPD');
215 me.setAttribute('data-doc-id', 'FFF');
216 me.setAttribute('data-text-id', '01460');
217 me.setAttribute('data-text-sigle', 'WPD/FFF/01460');
218 me.setAttribute('data-match-id', 'p119-120');
219 me.innerHTML = '<div><div class="snippet">check</div></div><p class="ref">me</p>';
220 return me;
221 };
222
223 function matchElementReal () {
224 var me = document.createElement('em');
225 me.innerHTML =
226 '<li data-match-id="p85183-85184"' +
227 ' data-text-sigle="GOE/AGI/00000"' +
228 ' 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"' +
229 ' 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;}"' +
230 ' id="GOE/AGI/00000#p85183-85184">' +
231 '<div>' +
232 '<div class="flag"></div>' +
233 '<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>' +
234 '</div>' +
235 '<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>' +
236 '</li>';
237 return me.firstChild;
238 };
239
240 var beforeAllFunc = function () {
241 // Override getMatchInfo API call
242 KorAP.API.getMatchInfo = function (x, param, cb) {
243 if (param['spans'] === undefined || param['spans'] === false)
244 cb({ "snippet": snippet });
245 else
246 cb({ "snippet": treeSnippet });
247 };
248 };
249
250 var afterAllFunc = function () {
251 KorAP.API.getMatchInfo = undefined;
252 // KorAP.annotationHelper = undefined;
253 var body = document.body;
254 for (var i in body.children) {
255 if (body.children[i].nodeType && body.children[i].nodeType === 1) {
256 if (!body.children[i].classList.contains("jasmine_html-reporter")) {
257 body.removeChild(body.children[i]);
258 };
259 };
260 };
261 };
262
Akron671fdb92017-09-12 18:09:46 +0200263
Nils Diewald7c8ced22015-04-15 19:21:00 +0000264 describe('KorAP.InfoLayer', function () {
Akrond8692de2018-07-26 13:06:01 +0200265 beforeAll(beforeAllFunc);
266 afterAll(afterAllFunc);
Nils Diewalda297f062015-04-02 00:23:46 +0000267
Nils Diewald7c8ced22015-04-15 19:21:00 +0000268 it('should be initializable', function () {
269 expect(
Akron671fdb92017-09-12 18:09:46 +0200270 function() { infoClass.create() }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000271 ).toThrow(new Error("Missing parameters"));
Nils Diewalda297f062015-04-02 00:23:46 +0000272
Nils Diewald7c8ced22015-04-15 19:21:00 +0000273 expect(
Akron671fdb92017-09-12 18:09:46 +0200274 function() { infoClass.create("base") }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000275 ).toThrow(new Error("Missing parameters"));
Nils Diewalda297f062015-04-02 00:23:46 +0000276
Nils Diewald7c8ced22015-04-15 19:21:00 +0000277 var layer = infoClass.create("base", "s");
278 expect(layer).toBeTruthy();
279 expect(layer.foundry).toEqual("base");
280 expect(layer.layer).toEqual("s");
281 expect(layer.type).toEqual("tokens");
Nils Diewalda297f062015-04-02 00:23:46 +0000282
Nils Diewald7c8ced22015-04-15 19:21:00 +0000283 layer = infoClass.create("cnx", "syn", "spans");
284 expect(layer).toBeTruthy();
285 expect(layer.foundry).toEqual("cnx");
286 expect(layer.layer).toEqual("syn");
287 expect(layer.type).toEqual("spans");
Nils Diewald58141332015-04-07 16:18:45 +0000288 });
289 });
Nils Diewalda297f062015-04-02 00:23:46 +0000290
Nils Diewalda297f062015-04-02 00:23:46 +0000291
Nils Diewald7c8ced22015-04-15 19:21:00 +0000292 describe('KorAP.Match', function () {
Akrond8692de2018-07-26 13:06:01 +0200293 beforeAll(beforeAllFunc);
294 afterAll(afterAllFunc);
295
Nils Diewald7c8ced22015-04-15 19:21:00 +0000296 var match = {
297 'corpusID' : 'WPD',
298 'docID' : 'UUU',
299 'textID' : '01912',
300 'matchID' : 'p121-122',
Akron0a6768f2016-07-13 18:00:43 +0200301 'textSigle' : 'WPD/UUU/01912',
Nils Diewald7c8ced22015-04-15 19:21:00 +0000302 'available' : available
303 };
304
Nils Diewald7c8ced22015-04-15 19:21:00 +0000305 it('should be initializable by Object', function () {
306 expect(function() {
Akron671fdb92017-09-12 18:09:46 +0200307 matchClass.create()
Nils Diewald7c8ced22015-04-15 19:21:00 +0000308 }).toThrow(new Error('Missing parameters'));
309
310 expect(matchClass.create(match)).toBeTruthy();
311
312 var m = matchClass.create(match);
Akron0a6768f2016-07-13 18:00:43 +0200313 expect(m.textSigle).toEqual("WPD/UUU/01912");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000314 expect(m.matchID).toEqual("p121-122");
315
316 // /corpus/WPD/UUU.01912/p121-122/matchInfo?spans=false&foundry=*
317 var m = matchClass.create(match);
318
319 // Spans:
320 var spans = m.getSpans();
321 expect(spans[0].foundry).toEqual("base");
322 expect(spans[0].layer).toEqual("s");
323
324 expect(spans[1].foundry).toEqual("corenlp");
325 expect(spans[1].layer).toEqual("c");
326
327 expect(spans[2].foundry).toEqual("corenlp");
328 expect(spans[2].layer).toEqual("s");
329
330 expect(spans[spans.length-1].foundry).toEqual("tt");
331 expect(spans[spans.length-1].layer).toEqual("s");
332
333 // Tokens:
334 var tokens = m.getTokens();
335 expect(tokens[0].foundry).toEqual("corenlp");
336 expect(tokens[0].layer).toEqual("ne");
337
338 expect(tokens[1].foundry).toEqual("corenlp");
339 expect(tokens[1].layer).toEqual("p");
340
341 expect(tokens[tokens.length-1].foundry).toEqual("tt");
342 expect(tokens[tokens.length-1].layer).toEqual("p");
Nils Diewald58141332015-04-07 16:18:45 +0000343 });
Nils Diewalda297f062015-04-02 00:23:46 +0000344
345
Akroncdb0baa2016-11-07 01:52:11 +0100346 it('should be initializable by Node 1', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000347 var m = matchClass.create(matchElementFactory());
Akron0a6768f2016-07-13 18:00:43 +0200348 expect(m.textSigle).toEqual("WPD/FFF/01460");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000349 expect(m.matchID).toEqual("p119-120");
Nils Diewalda297f062015-04-02 00:23:46 +0000350
Nils Diewald7c8ced22015-04-15 19:21:00 +0000351 // Spans:
352 var spans = m.getSpans();
353 expect(spans[0].foundry).toEqual("base");
354 expect(spans[0].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000355
Nils Diewald7c8ced22015-04-15 19:21:00 +0000356 expect(spans[1].foundry).toEqual("corenlp");
357 expect(spans[1].layer).toEqual("c");
Nils Diewalda297f062015-04-02 00:23:46 +0000358
Nils Diewald7c8ced22015-04-15 19:21:00 +0000359 expect(spans[2].foundry).toEqual("corenlp");
360 expect(spans[2].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000361
Nils Diewald7c8ced22015-04-15 19:21:00 +0000362 expect(spans[spans.length-1].foundry).toEqual("tt");
363 expect(spans[spans.length-1].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000364
Nils Diewald7c8ced22015-04-15 19:21:00 +0000365 // Tokens:
366 var tokens = m.getTokens();
367 expect(tokens[0].foundry).toEqual("corenlp");
368 expect(tokens[0].layer).toEqual("ne");
Nils Diewalda297f062015-04-02 00:23:46 +0000369
Nils Diewald7c8ced22015-04-15 19:21:00 +0000370 expect(tokens[1].foundry).toEqual("corenlp");
371 expect(tokens[1].layer).toEqual("p");
Nils Diewalda297f062015-04-02 00:23:46 +0000372
Nils Diewald7c8ced22015-04-15 19:21:00 +0000373 expect(tokens[tokens.length-1].foundry).toEqual("tt");
374 expect(tokens[tokens.length-1].layer).toEqual("p");
Nils Diewalda297f062015-04-02 00:23:46 +0000375
Nils Diewald7c8ced22015-04-15 19:21:00 +0000376 });
Nils Diewalda297f062015-04-02 00:23:46 +0000377
Akroncdb0baa2016-11-07 01:52:11 +0100378 it('should be initializable by Node 2', function () {
379 var ele = matchElementReal();
380 var m = matchClass.create(ele);
381 expect(m.textSigle).toEqual("GOE/AGI/00000");
382 expect(m.matchID).toEqual("p85183-85184");
383 });
384
385
Nils Diewald7c8ced22015-04-15 19:21:00 +0000386 it('should react to gui actions', function () {
387 var e = matchElementFactory();
Nils Diewalda297f062015-04-02 00:23:46 +0000388
Nils Diewald7c8ced22015-04-15 19:21:00 +0000389 expect(e.classList.contains('active')).toBe(false);
390 expect(e["_match"]).toBe(undefined);
Nils Diewalda297f062015-04-02 00:23:46 +0000391
Nils Diewald7c8ced22015-04-15 19:21:00 +0000392 var m = matchClass.create(e);
393
394 expect(e.classList.contains('active')).toBe(false);
395 expect(e["_match"]).not.toBe(undefined);
396
397 // Open the match
398 m.open();
399
400 expect(e.classList.contains('active')).toBe(true);
401 expect(e["_match"]).not.toBe(undefined);
402
Akronbfe912c2018-07-17 19:30:52 +0200403 actions = e.querySelector("p.ref > div.action.button-group").children;
Akrond141a362018-07-10 18:12:13 +0200404
Akronbfe912c2018-07-17 19:30:52 +0200405 expect(actions[0].getAttribute("class")).toEqual("metatable");
Akronc296ca22018-04-24 16:35:26 +0200406 expect(actions[1].getAttribute("class")).toEqual("info");
407 expect(actions[2].getAttribute("class")).toEqual("tree");
408
Nils Diewald7c8ced22015-04-15 19:21:00 +0000409 // Close the match
Akronec6bb8e2018-08-29 13:07:56 +0200410 m.minimize();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000411 expect(e.classList.contains('active')).toBe(false);
412 expect(e["_match"]).not.toBe(undefined);
Nils Diewald58141332015-04-07 16:18:45 +0000413 });
Nils Diewalda297f062015-04-02 00:23:46 +0000414
Akrond8692de2018-07-26 13:06:01 +0200415 it('should open tree menu', function () {
Akronc296ca22018-04-24 16:35:26 +0200416 var e = matchElementFactory();
417 var m = matchClass.create(e);
418 m.open();
Akronbfe912c2018-07-17 19:30:52 +0200419 var relation = e.querySelector("p.ref > div.action.button-group > span:nth-of-type(3)");
Akronc296ca22018-04-24 16:35:26 +0200420 expect(relation.getAttribute("class")).toEqual("tree");
Akron52ed22d2018-07-11 17:05:19 +0200421 expect(document.getElementsByClassName("button-group-list").length).toEqual(0);
Akronc296ca22018-04-24 16:35:26 +0200422
423 expect(document.activeElement.tagName).toEqual("BODY");
424
425 // Show menu
426 relation.click();
Akron52ed22d2018-07-11 17:05:19 +0200427 expect(document.getElementsByClassName("button-group-list").length).toEqual(1);
Akronc296ca22018-04-24 16:35:26 +0200428
429 expect(document.activeElement.tagName).toEqual("UL");
430
431 // Choose first tree
Akron52ed22d2018-07-11 17:05:19 +0200432 document.getElementsByClassName("button-group-list")[0].getElementsByTagName("li")[1].click();
Akronc296ca22018-04-24 16:35:26 +0200433 expect(e.querySelector("div.matchinfo div.matchtree h6 span").innerText).toEqual("corenlp");
434
435 // This should blur the focus
436 expect(document.activeElement.tagName).toEqual("BODY");
437 });
438
439 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000440
Akron7f9a6a32018-07-18 15:05:23 +0200441 describe('KorAP.TableView', function () {
Akrond8692de2018-07-26 13:06:01 +0200442 beforeAll(beforeAllFunc);
443 afterAll(afterAllFunc);
444
Akron7f9a6a32018-07-18 15:05:23 +0200445 var table;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000446
Akron7f9a6a32018-07-18 15:05:23 +0200447 var matchObj = matchClass.create(match);
448 var tableObj = tableClass.create(matchObj);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000449
450 var table1, table2;
451
Nils Diewald7c8ced22015-04-15 19:21:00 +0000452 it('should fail to load a table async', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200453 expect(tableObj).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000454
Akron7f9a6a32018-07-18 15:05:23 +0200455 tableObj.getData([], function (tablen) {
Akron671fdb92017-09-12 18:09:46 +0200456 table1 = tablen;
457 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000458 });
459 });
460
Akron671fdb92017-09-12 18:09:46 +0200461
Akronaeeb8252018-09-19 18:51:00 +0200462 xit('should\'nt be parsable (async)', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000463 expect(table1).not.toBeTruthy();
464 });
465
Nils Diewald7c8ced22015-04-15 19:21:00 +0000466
Nils Diewald7c8ced22015-04-15 19:21:00 +0000467 it('should be retrieved async', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200468 expect(tableObj).toBeTruthy();
469 tableObj.getData(undefined, function (x) {
Akron671fdb92017-09-12 18:09:46 +0200470 table = x;
471 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000472 });
473 });
Nils Diewalda297f062015-04-02 00:23:46 +0000474
Akron7f9a6a32018-07-18 15:05:23 +0200475 it('should parse into a table (async)', function () {
476 expect(table).toBeTruthy();
Akron5b1a6af2018-02-05 15:41:16 +0100477
Akron7f9a6a32018-07-18 15:05:23 +0200478 expect(table.length()).toBe(3);
479
480 expect(table.getToken(0)).toBe("meist");
481 expect(table.getToken(1)).toBe("deutlich");
482 expect(table.getToken(2)).toBe("leistungsfähiger");
483
484 expect(table.getValue(0, "cnx", "p")[0]).toBe("ADV");
485 expect(table.getValue(0, "cnx", "syn")[0]).toBe("@PREMOD");
486 expect(table.getValue(0, "mate", "l")[0]).toBe("meist");
487 expect(table.getValue(0, "mate", "l")[1]).toBeUndefined();
488
489 expect(table.getValue(2, "cnx", "l")[0]).toBe("fähig");
490 expect(table.getValue(2, "cnx", "l")[1]).toBe("leistung");
491 });
492
493 it('should be rendered async', function () {
Akron5b1a6af2018-02-05 15:41:16 +0100494 var e = table.element().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000495 expect(e.nodeName).toBe('TABLE');
496 expect(e.children[0].nodeName).toBe('THEAD');
497 var tr = e.children[0].children[0];
498 expect(tr.nodeName).toBe('TR');
499 expect(tr.children[0].nodeName).toBe('TH');
Nils Diewald58141332015-04-07 16:18:45 +0000500
Nils Diewald7c8ced22015-04-15 19:21:00 +0000501 expect(tr.children[0].firstChild.nodeValue).toBe('Foundry');
502 expect(tr.children[1].firstChild.nodeValue).toBe('Layer');
503 expect(tr.children[2].firstChild.nodeValue).toBe('meist');
Akronad1e46a2018-09-19 15:55:40 +0200504 expect(tr.children[2].classList.contains('mark')).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000505 expect(tr.children[3].firstChild.nodeValue).toBe('deutlich');
Akronad1e46a2018-09-19 15:55:40 +0200506 expect(tr.children[3].classList.contains('mark')).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000507 expect(tr.children[4].firstChild.nodeValue).toBe('leistungsfähiger');
Akronad1e46a2018-09-19 15:55:40 +0200508 expect(tr.children[4].classList.contains('mark')).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000509
510 // first row
511 tr = e.children[1].children[0];
512 expect(tr.nodeName).toBe('TR');
513 expect(tr.getAttribute('tabindex')).toEqual('0');
514 expect(tr.children[0].nodeName).toBe('TH');
515 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
516 expect(tr.children[1].firstChild.nodeValue).toEqual('l');
517 expect(tr.children[2].firstChild.nodeValue).toEqual('meist');
518 expect(tr.children[3].firstChild.nodeValue).toEqual('deutlich');
Akron47774c42017-07-03 20:14:55 +0200519 expect(tr.children[4].firstChild.firstChild.nodeValue).toEqual('fähig');
520 expect(tr.children[4].lastChild.firstChild.nodeValue).toEqual('leistung');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000521
522 // second row
523 tr = e.children[1].children[1];
524 expect(tr.nodeName).toBe('TR');
525 expect(tr.getAttribute('tabindex')).toEqual('0');
526 expect(tr.children[0].nodeName).toBe('TH');
527 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
528 expect(tr.children[1].firstChild.nodeValue).toEqual('p');
529 expect(tr.children[2].firstChild.nodeValue).toEqual('ADV');
530 expect(tr.children[3].firstChild.nodeValue).toEqual('A');
Akron47774c42017-07-03 20:14:55 +0200531 expect(tr.children[4].firstChild.firstChild.nodeValue).toEqual('A');
532 expect(tr.children[4].lastChild.firstChild.nodeValue).toEqual('ADJA');
Akronf2279c42017-12-21 13:48:46 +0100533
534 expect(tr.children[4].firstChild.getAttribute("title")).toEqual('Adjective');
535 expect(tr.children[2].getAttribute("title")).toEqual('Adverb');
536
Nils Diewald58141332015-04-07 16:18:45 +0000537 });
Akron7f9a6a32018-07-18 15:05:23 +0200538
539
540 it('should parse into a table view (sync)', function () {
541 var matchElement = matchElementFactory();
542 expect(matchElement.tagName).toEqual('LI');
543
544 // Match
545 expect(matchElement.children[0].tagName).toEqual('DIV');
546
547 // snippet
548 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
549 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
550 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
551
552 // reference
553 expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
554 expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
555
556 // not yet
557 expect(matchElement.children[0].children[1]).toBe(undefined);
558
559 /*
560 var info = matchClass.create(matchElement).info();
561 info.showTable();
562 */
563 var matchObj = matchClass.create(matchElement);
564 matchObj.open();
565
566 // Match
567 expect(matchElement.children[0].tagName).toEqual('DIV');
568
569 // snippet
570 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
571
572 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
573
574 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
575
576 // reference
577
578 expect(matchElement.children[2].classList.contains('ref')).toBeTruthy();
579 expect(matchElement.children[2].childNodes[1].nodeValue).toEqual('me');
580
581 // Add table
582 matchObj.panel.addTable();
583
584 // now
585 var infotable = matchElement.children[1];
586 expect(infotable.tagName).toEqual('DIV');
587
588 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
589
590 expect(infotable.firstChild.firstChild.firstChild.classList.contains('matchtable')).toBeTruthy();
591
592 // expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
593 });
594
Nils Diewald58141332015-04-07 16:18:45 +0000595 });
Nils Diewalda297f062015-04-02 00:23:46 +0000596
Akron7f9a6a32018-07-18 15:05:23 +0200597 describe('KorAP.RelationsView', function () {
Akrond8692de2018-07-26 13:06:01 +0200598 beforeAll(beforeAllFunc);
599 afterAll(afterAllFunc);
600
Nils Diewald7c8ced22015-04-15 19:21:00 +0000601 var tree;
Nils Diewalda297f062015-04-02 00:23:46 +0000602
Nils Diewald7c8ced22015-04-15 19:21:00 +0000603 it('should be rendered async 1', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200604 var matchObj = matchClass.create(match);
605 var relObj = relClass.create(matchObj);
606 expect(relObj).toBeTruthy();
607 relObj.getData(undefined, undefined, "spans", function (y) {
Akron671fdb92017-09-12 18:09:46 +0200608 tree = y;
609 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000610 });
611 });
Nils Diewalda297f062015-04-02 00:23:46 +0000612
Nils Diewald7c8ced22015-04-15 19:21:00 +0000613 it('should be rendered async 2', function () {
Akron7f9a6a32018-07-18 15:05:23 +0200614 expect(tree).toBeTruthy();
615 expect(tree.nodes()).toEqual(49);
616
Nils Diewald7c8ced22015-04-15 19:21:00 +0000617 var e = tree.element();
618 expect(e.nodeName).toEqual('svg');
619 expect(e.getElementsByTagName('g').length).toEqual(48);
Nils Diewald58141332015-04-07 16:18:45 +0000620 });
Akron7f9a6a32018-07-18 15:05:23 +0200621
622
623 it('should add a tree view async 2', function () {
624 var matchElement = matchElementFactory();
625 var matchObj = matchClass.create(matchElement);
626 matchObj.open();
627 matchObj.panel.addTree('mate', 'beebop', 'spans', function () {
628 done();
629 });
630
631 // With added tree
632 var tree = matchElement.children[1].firstChild.firstChild.firstChild;
633 expect(tree.tagName).toEqual('DIV');
634 expect(tree.classList.contains('matchtree')).toBeTruthy();
635 expect(tree.children[0].tagName).toEqual('H6');
636 expect(tree.children[0].children[0].tagName).toEqual('SPAN');
637 expect(tree.children[0].children[0].firstChild.nodeValue).toEqual('mate');
638 expect(tree.children[0].children[1].tagName).toEqual('SPAN');
639 expect(tree.children[0].children[1].firstChild.nodeValue).toEqual('beebop');
640
641 expect(tree.children[1].tagName).toEqual('DIV');
642 });
643
Nils Diewald58141332015-04-07 16:18:45 +0000644 });
Nils Diewalda297f062015-04-02 00:23:46 +0000645
Nils Diewald7c8ced22015-04-15 19:21:00 +0000646
647 describe('KorAP.MatchTreeItem', function () {
Akrond8692de2018-07-26 13:06:01 +0200648 beforeAll(beforeAllFunc);
649 afterAll(afterAllFunc);
650
Nils Diewald7c8ced22015-04-15 19:21:00 +0000651 it('should be initializable', function () {
652 var mi = matchTreeItemClass.create(['cnx/c', 'cnx', 'c'])
653 expect(mi.element().firstChild.nodeValue).toEqual('cnx/c');
654 expect(mi.lcField()).toEqual(' cnx/c');
655 expect(mi.foundry()).toEqual('cnx');
656 expect(mi.layer()).toEqual('c');
657 });
Nils Diewalda297f062015-04-02 00:23:46 +0000658 });
Nils Diewalda297f062015-04-02 00:23:46 +0000659
660
Akron671fdb92017-09-12 18:09:46 +0200661 describe('KorAP.MatchRelation', function () {
Akrond8692de2018-07-26 13:06:01 +0200662 beforeAll(beforeAllFunc);
663 afterAll(afterAllFunc);
Akron671fdb92017-09-12 18:09:46 +0200664
665 var relExample = "<span class=\"context-left\"></span>" +
666 "<span class=\"match\">" +
667 " <span xml:id=\"token-GOE/AGA/01784-p199\">" +
668 " <span xlink:title=\"malt/d:ADV\" " +
669 " xlink:type=\"simple\" " +
670 " xlink:href=\"#token-GOE/AGA/01784-p199\">dann</span>" +
671 " </span>" +
672 " zog " +
673 " <span xlink:title=\"malt/d:SUBJ\" " +
674 " xlink:type=\"simple\" " +
675 " xlink:href=\"#token-GOE/AGA/01784-p199\">ich</span>" +
676 " <span xml:id=\"token-GOE/AGA/01784-p202\">" +
677 " <span xlink:title=\"malt/d:OBJA\" " +
678 " xlink:type=\"simple\" " +
679 " xlink:href=\"#token-GOE/AGA/01784-p199\">mich</span>" +
680 " </span>" +
681 "</span>" +
682 "<span class=\"context-right\"></span>";
683
684
685 it('should be initializable', function () {
Akrond8692de2018-07-26 13:06:01 +0200686 var tree = matchRelClass.create();
Akron671fdb92017-09-12 18:09:46 +0200687 expect(tree.size()).toBe(0);
688 });
689
690 it('should be parse string data', function () {
Akrond8692de2018-07-26 13:06:01 +0200691 var tree = matchRelClass.create(relExample);
Akron671fdb92017-09-12 18:09:46 +0200692 expect(tree.size()).toBe(4);
693 });
Akron671fdb92017-09-12 18:09:46 +0200694 });
695
696
Nils Diewald7c8ced22015-04-15 19:21:00 +0000697 describe('KorAP.MatchTreeMenu', function () {
Akrond8692de2018-07-26 13:06:01 +0200698 beforeAll(beforeAllFunc);
699 afterAll(afterAllFunc);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000700
701 it('should be initializable', function () {
Akrond8692de2018-07-26 13:06:01 +0200702 var menu = matchTreeMenuClass.create([
Akron671fdb92017-09-12 18:09:46 +0200703 ['cnx/c', 'cnx', 'c'],
704 ['xip/c', 'xip', 'c']
Akrond8692de2018-07-26 13:06:01 +0200705 ], matchTreeItemClass);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000706
Akrond8692de2018-07-26 13:06:01 +0200707 expect(menu.itemClass()).toEqual(matchTreeItemClass);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000708 expect(menu.element().nodeName).toEqual('UL');
Akronaba7a5a2016-08-15 21:58:33 +0200709 expect(menu.element().classList.contains('visible')).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000710 expect(menu.limit()).toEqual(6);
711 menu.show();
Akronaba7a5a2016-08-15 21:58:33 +0200712 expect(menu.element().classList.contains('visible')).toBeTruthy();
Akronc1457bf2015-06-11 19:24:00 +0200713 expect(menu.item(0).active()).toBe(false);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000714 });
Nils Diewalda297f062015-04-02 00:23:46 +0000715 });
hebasta999d6c12018-04-23 12:44:59 +0200716
717 //Test display and sorting of meta information
718 describe('KorAP.Meta', function(){
Akrond8692de2018-07-26 13:06:01 +0200719 beforeAll(beforeAllFunc);
720 afterAll(afterAllFunc);
721
722 var met = metaClass.create(match, fields);
hebasta999d6c12018-04-23 12:44:59 +0200723 var mel = met.element();
724
725 // Meta information should be parsed into a list
726 it('should parse in a meta view', function(){
Akronfa32c9d2018-11-20 15:39:18 +0100727 expect(mel.tagName).toEqual('DL');
728 expect(mel.children[0].tagName).toEqual('DIV');
729 expect(mel.children[0].children[0].tagName).toEqual('DT');
730 expect(mel.children[0].children[0].attributes[0].name).toEqual('title');
731 expect(mel.children[0].children[1].tagName).toEqual('DD');
732 expect(mel.children[0].children[1].getAttribute('data-type')).toEqual('type:text')
hebasta999d6c12018-04-23 12:44:59 +0200733
Akronfa32c9d2018-11-20 15:39:18 +0100734 expect(mel.children[0].children[0].firstChild.nodeValue).toEqual('author');
735 expect(mel.children[0].children[1].firstChild.nodeValue).toEqual('Sprachpfleger, u.a.');
736 expect(mel.children[0].children[0].attributes[0].value).toEqual('author');
hebasta999d6c12018-04-23 12:44:59 +0200737 });
738
739
Akronfa32c9d2018-11-20 15:39:18 +0100740 /* The keywords in the meta information list should be formatted to be able
741 to chose each keyword separately in the corpusByMatch assistant. */
742 it('keywords should be formatted', function(){
hebasta999d6c12018-04-23 12:44:59 +0200743
Akronfa32c9d2018-11-20 15:39:18 +0100744 //type:string or type:keyword should b not relevant
745 expect(mel.children[1].children[1].getAttribute('data-type')).toEqual('type:string')
746 expect(mel.children[1].children[1].classList.contains('metakeyvalues')).toBeTruthy;
747 expect(mel.children[1].children[1].children[0].tagName).toEqual('DIV');
748 expect(mel.children[1].children[1].children[0].firstChild.nodeValue).toEqual('corenlp');
749 expect(mel.children[1].children[1].children[1].tagName).toEqual('DIV');
750 expect(mel.children[1].children[1].children[1].firstChild.nodeValue).toEqual('corenlp\/constituency');
751
752 expect(mel.children[2].children[1].classList.contains('metakeyvalues')).toBeTruthy;
753 expect(mel.children[2].children[1].children[0].tagName).toEqual('DIV');
754 expect(mel.children[2].children[1].children[0].firstChild.nodeValue).toEqual('kultur');
755 expect(mel.children[2].children[1].children[1].tagName).toEqual('DIV');
756 expect(mel.children[2].children[1].children[1].firstChild.nodeValue).toEqual('film');
hebasta999d6c12018-04-23 12:44:59 +0200757 });
Akrona0ea3c32018-12-14 18:33:48 +0100758
759 it('attachements should be formatted', function(){
Akrond3bb85b2019-02-08 10:15:13 +0100760 //type:attachement with a link
Akrona0ea3c32018-12-14 18:33:48 +0100761 expect(mel.children[3].children[1].getAttribute('data-type')).toEqual('type:attachement')
762 expect(mel.children[3].children[1].classList.contains('metakeyvalues')).toBeFalsy;
763 expect(mel.children[3].children[0].firstChild.nodeValue).toEqual('xlink');
764 expect(mel.children[3].children[1].firstChild.textContent).toEqual('Cool');
765 expect(mel.children[3].children[1].firstChild.tagName).toEqual('A');
766 expect(mel.children[3].children[1].firstChild.getAttribute('href')).toEqual('https://de.wikipedia.org/wiki/Beispiel');
Akrond3bb85b2019-02-08 10:15:13 +0100767
768 //type:attachement with plain text
769 expect(mel.children[4].children[1].getAttribute('data-type')).toEqual('type:attachement')
770 expect(mel.children[4].children[1].classList.contains('metakeyvalues')).toBeFalsy;
771 expect(mel.children[4].children[0].firstChild.nodeValue).toEqual('z-reference');
772 expect(mel.children[4].children[1].firstChild.nodeValue).toEqual('This is a reference');
773 });
Akrona0ea3c32018-12-14 18:33:48 +0100774
775
hebasta999d6c12018-04-23 12:44:59 +0200776
Akronfa32c9d2018-11-20 15:39:18 +0100777 // Meta information should be sorted alphabetically
778 it('should be alphabetically sorted', function(){
779 var a = mel.children[0].children[0].firstChild.nodeValue;
780 var b = mel.children[1].children[0].firstChild.nodeValue;
781 var c = mel.children[2].children[0].firstChild.nodeValue;
782 expect(a.localeCompare(b)).toBe(-1);
783 expect(b.localeCompare(c)).toBe(-1);
Akrona0ea3c32018-12-14 18:33:48 +0100784 });
785
786
787 it('should handle attachements', function () {
788 let uri = attachementClass.create("data:text/plain;title=new,Hallo");
789 expect(uri.contentType).toEqual("text/plain");
790
791 expect(uri.payload).toEqual("Hallo");
792 expect(uri.base64).toBeFalsy();
793 expect(uri.isLink).toBeFalsy();
794 expect(uri.param["title"]).toEqual("new");
795
796 uri = attachementClass.create("data:application/x.korap-link,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("https://de.wikipedia.org/wiki/Beispiel");
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:application/x.korap-link;title=Das ist ein Titel,https://de.wikipedia.org/wiki/Beispiel");
808 expect(uri.contentType).toEqual("application/x.korap-link");
809 expect(uri.payload).toEqual("https://de.wikipedia.org/wiki/Beispiel");
810 expect(uri.base64).toBeFalsy();
811 expect(uri.isLink).toBeTruthy();
812 expect(uri.inline().textContent).toEqual("Das ist ein Titel");
813 expect(uri.inline().nodeType).toEqual(1);
814 expect(uri.inline().tagName).toEqual("A");
815 expect(uri.inline().getAttribute("rel")).toEqual("noopener noreferrer");
816
817
818 uri = attachementClass.create("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D");
819 expect(uri.contentType).toEqual("text/plain");
820 expect(uri.payload).toEqual("Hello, World!");
821 expect(uri.base64).toBeTruthy();
822 expect(uri.isLink).toBeFalsy();
823 expect(uri.inline().nodeType).toEqual(3);
824 expect(uri.inline().textContent).toEqual("Hello, World!");
825
826 uri = attachementClass.create("data:text/plain;title= new ; subTitle = old ;base64,SGVsbG8sIFdvcmxkIQ%3D%3D");
827 expect(uri.contentType).toEqual("text/plain");
828 expect(uri.payload).toEqual("Hello, World!");
829 expect(uri.param["title"]).toEqual("new");
830 expect(uri.param["subTitle"]).toEqual("old");
831 expect(uri.base64).toBeTruthy();
832 expect(uri.isLink).toBeFalsy();
833 expect(uri.inline().nodeType).toEqual(3);
834 expect(uri.inline().textContent).toEqual("Hello, World!");
835 });
hebasta999d6c12018-04-23 12:44:59 +0200836 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000837 // table = view.toTable();
838 // table.sortBy('');
839 // table.element();
840 // tree = view.toTree();
841 // tree.element();
Nils Diewalda297f062015-04-02 00:23:46 +0000842});