blob: b27ddbda35ec65f0bf9153c3bc18a66f7bc7f484 [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',
12 'hint/foundries/cnx',
13 'hint/foundries/mate'], function (
14 matchClass,
15 tableClass,
16 relClass,
17 panelClass,
18 metaClass,
19 infoClass,
20 matchTreeItemClass,
21 matchRelClass,
22 matchTreeMenuClass) {
Nils Diewald7c8ced22015-04-15 19:21:00 +000023
Akrond8692de2018-07-26 13:06:01 +020024 var available = [
25 'base/s=spans',
26 'corenlp/c=spans',
27 'corenlp/ne=tokens',
28 'corenlp/p=tokens',
29 'corenlp/s=spans',
30 'glemm/l=tokens',
31 'mate/l=tokens',
32 'mate/m=tokens',
33 'mate/p=tokens',
34 'opennlp/p=tokens',
35 'opennlp/s=spans',
36 'tt/l=tokens',
37 'tt/p=tokens',
38 'tt/s=spans'
39 ];
Nils Diewalda297f062015-04-02 00:23:46 +000040
Akrond8692de2018-07-26 13:06:01 +020041 var match = {
42 'corpusID' : 'WPD',
43 'docID' : 'UUU',
44 'textID' : '01912',
45 'matchID' : 'p121-122',
46 'textSigle' : 'WPD/UUU/01912',
47 'available' : available
Nils Diewalda297f062015-04-02 00:23:46 +000048 };
Akrond8692de2018-07-26 13:06:01 +020049
50
51 var fields = [
52 {
53 "@type": "koral:field",
54 "key": "author",
55 "type": "type:text",
56 "value": "Sprachpfleger, u.a."
57 },
58 {
59 "@type": "koral:field",
60 "key": "textClass",
Akrond45a1702018-11-19 18:15:17 +010061 "type": "type:keywords", // May not be necessary
Akrond8692de2018-07-26 13:06:01 +020062 "value": ["kultur", "film"]
63 },
64 {
65 "@type":"koral:field",
66 "key":"foundries",
67 "type":"type:string",
68 "value":[
69 "corenlp",
70 "corenlp\/constituency",
71 "corenlp\/morpho",
72 "corenlp\/sentences",
73 "dereko",
74 "dereko\/structure",
75 "dereko\/structure\/base-sentences-paragraphs-pagebreaks",
76 "opennlp",
77 "opennlp\/morpho",
78 "opennlp\/sentences"
79 ]
80 }
81 ];
82
83
84 var snippet = "<span title=\"cnx/l:meist\">" +
85 " <span title=\"cnx/p:ADV\">" +
86 " <span title=\"cnx/syn:@PREMOD\">" +
87 " <span title=\"mate/l:meist\">" +
88 " <span title=\"mate/l:meist\">" +
89 " <span title=\"mate/p:ADV\">" +
90 " <span title=\"opennlp/p:ADV\">meist</span>" +
91 " </span>" +
92 " </span>" +
93 " </span>" +
94 " </span>" +
95 " </span>" +
96 "</span>" +
Akronad1e46a2018-09-19 15:55:40 +020097 "<mark>" +
Akrond8692de2018-07-26 13:06:01 +020098 "<span title=\"cnx/l:deutlich\">" +
99 " <span title=\"cnx/p:A\">" +
100 " <span title=\"cnx/syn:@PREMOD\">" +
101 " <span title=\"mate/l:deutlich\">" +
102 " <span title=\"mate/m:degree:pos\">" +
103 " <span title=\"mate/p:ADJD\">" +
104 " <span title=\"opennlp/p:ADJD\">deutlich</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:fähig\">" +
113 " <span title=\"cnx/l:leistung\">" +
114 " <span title=\"cnx/p:A\">" +
115 " <span title=\"cnx/p:ADJA\">" +
116 " <span title=\"cnx/syn:@NH\">" +
117 " <span title=\"mate/l:leistungsfähig\">" +
118 " <span title=\"mate/m:degree:comp\">" +
119 " <span title=\"mate/p:ADJD\">" +
120 " <span title=\"opennlp/p:ADJD\">leistungsfähiger</span>" +
121 " </span>" +
122 " </span>" +
123 " </span>" +
124 " </span>" +
125 " </span>" +
126 " </span>" +
127 " </span>" +
128 "</span>";
129
130 var treeSnippet =
131 "<span class=\"context-left\"></span>" +
132 "<span class=\"match\">" +
133 " <span title=\"xip/c:MC\">" +
134 " <span title=\"xip/c:TOP\">" +
135 " <span title=\"xip/c:PP\">" +
136 " <span title=\"xip/c:PREP\">Mit</span>" +
137 " <span title=\"xip/c:NP\">" +
138 " <span title=\"xip/c:DET\">dieser</span>" +
139 " <span title=\"xip/c:NPA\">" +
140 " <span title=\"xip/c:NOUN\">Methode</span>" +
141 " </span>" +
142 " </span>" +
143 " </span>" +
144 " <span title=\"xip/c:VERB\">ist</span>" +
145 " <mark>" +
146 " <span title=\"xip/c:NP\">" +
147 " <span title=\"xip/c:PRON\">es</span>" +
148 " </span>" +
149 " <span title=\"xip/c:AP\">" +
150 " <span title=\"xip/c:ADV\">nun</span>" +
151 " <span title=\"xip/c:ADJ\">möglich</span>" +
152 " </span>" +
153 " </mark>" +
154 " <span title=\"xip/c:ADV\">z. B.</span>" +
155 " <span title=\"xip/c:NPA\">" +
156 " <span title=\"xip/c:NP\">" +
157 " <span title=\"xip/c:NOUN\">Voice</span>" +
158 " </span>" +
159 " </span>" + "(" +
160 " <span title=\"xip/c:INS\">" +
161 " <span title=\"xip/c:NPA\">" +
162 " <span title=\"xip/c:NP\">" +
163 " <span title=\"xip/c:NOUN\">Sprache</span>" +
164 " </span>" +
165 " </span>" +
166 " </span>" + ")" +
167 " <span title=\"xip/c:VERB\">bevorzugt</span>" +
168 " <span title=\"xip/c:PP\">" +
169 " <span title=\"xip/c:PREP\">in</span>" +
170 " <span title=\"xip/c:NP\">" +
171 " <span title=\"xip/c:PRON\">der</span>" +
172 " </span>" +
173 " <span title=\"xip/c:NPA\">" +
174 " <span title=\"xip/c:NP\">" +
175 " <span title=\"xip/c:NOUN\">Bridge</span>" +
176 " </span>" +
177 " </span>" +
178 " </span>" +
179 " <span title=\"xip/c:INFC\">" +
180 " <span title=\"xip/c:INS\">" +
181 " <span title=\"xip/c:VERB\">weiterzugeben</span>" +
182 " </span>" +
183 " </span>" +
184 " </span>" +
185 " </span>" +
186 "</span>" +
187 "<span class=\"context-right\"></span>";
188
189
190 function matchElementFactory () {
191 var me = document.createElement('li');
192
193 me.setAttribute(
194 'data-available-info',
195 'base/s=spans corenlp/c=spans corenlp/ne=tokens corenlp/p=tokens' +
196 ' corenlp/s=spans glemm/l=tokens mate/l=tokens mate/m=tokens' +
197 ' mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens' +
198 ' tt/p=tokens tt/s=spans');
199
200 me.setAttribute('data-corpus-id', 'WPD');
201 me.setAttribute('data-doc-id', 'FFF');
202 me.setAttribute('data-text-id', '01460');
203 me.setAttribute('data-text-sigle', 'WPD/FFF/01460');
204 me.setAttribute('data-match-id', 'p119-120');
205 me.innerHTML = '<div><div class="snippet">check</div></div><p class="ref">me</p>';
206 return me;
207 };
208
209 function matchElementReal () {
210 var me = document.createElement('em');
211 me.innerHTML =
212 '<li data-match-id="p85183-85184"' +
213 ' data-text-sigle="GOE/AGI/00000"' +
214 ' 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"' +
215 ' 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;}"' +
216 ' id="GOE/AGI/00000#p85183-85184">' +
217 '<div>' +
218 '<div class="flag"></div>' +
219 '<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>' +
220 '</div>' +
221 '<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>' +
222 '</li>';
223 return me.firstChild;
224 };
225
226 var beforeAllFunc = function () {
227 // Override getMatchInfo API call
228 KorAP.API.getMatchInfo = function (x, param, cb) {
229 if (param['spans'] === undefined || param['spans'] === false)
230 cb({ "snippet": snippet });
231 else
232 cb({ "snippet": treeSnippet });
233 };
234 };
235
236 var afterAllFunc = function () {
237 KorAP.API.getMatchInfo = undefined;
238 // KorAP.annotationHelper = undefined;
239 var body = document.body;
240 for (var i in body.children) {
241 if (body.children[i].nodeType && body.children[i].nodeType === 1) {
242 if (!body.children[i].classList.contains("jasmine_html-reporter")) {
243 body.removeChild(body.children[i]);
244 };
245 };
246 };
247 };
248
Akron671fdb92017-09-12 18:09:46 +0200249
Nils Diewald7c8ced22015-04-15 19:21:00 +0000250 describe('KorAP.InfoLayer', function () {
Akrond8692de2018-07-26 13:06:01 +0200251 beforeAll(beforeAllFunc);
252 afterAll(afterAllFunc);
Nils Diewalda297f062015-04-02 00:23:46 +0000253
Nils Diewald7c8ced22015-04-15 19:21:00 +0000254 it('should be initializable', function () {
255 expect(
Akron671fdb92017-09-12 18:09:46 +0200256 function() { infoClass.create() }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000257 ).toThrow(new Error("Missing parameters"));
Nils Diewalda297f062015-04-02 00:23:46 +0000258
Nils Diewald7c8ced22015-04-15 19:21:00 +0000259 expect(
Akron671fdb92017-09-12 18:09:46 +0200260 function() { infoClass.create("base") }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000261 ).toThrow(new Error("Missing parameters"));
Nils Diewalda297f062015-04-02 00:23:46 +0000262
Nils Diewald7c8ced22015-04-15 19:21:00 +0000263 var layer = infoClass.create("base", "s");
264 expect(layer).toBeTruthy();
265 expect(layer.foundry).toEqual("base");
266 expect(layer.layer).toEqual("s");
267 expect(layer.type).toEqual("tokens");
Nils Diewalda297f062015-04-02 00:23:46 +0000268
Nils Diewald7c8ced22015-04-15 19:21:00 +0000269 layer = infoClass.create("cnx", "syn", "spans");
270 expect(layer).toBeTruthy();
271 expect(layer.foundry).toEqual("cnx");
272 expect(layer.layer).toEqual("syn");
273 expect(layer.type).toEqual("spans");
Nils Diewald58141332015-04-07 16:18:45 +0000274 });
275 });
Nils Diewalda297f062015-04-02 00:23:46 +0000276
Nils Diewalda297f062015-04-02 00:23:46 +0000277
Nils Diewald7c8ced22015-04-15 19:21:00 +0000278 describe('KorAP.Match', function () {
Akrond8692de2018-07-26 13:06:01 +0200279 beforeAll(beforeAllFunc);
280 afterAll(afterAllFunc);
281
Nils Diewald7c8ced22015-04-15 19:21:00 +0000282 var match = {
283 'corpusID' : 'WPD',
284 'docID' : 'UUU',
285 'textID' : '01912',
286 'matchID' : 'p121-122',
Akron0a6768f2016-07-13 18:00:43 +0200287 'textSigle' : 'WPD/UUU/01912',
Nils Diewald7c8ced22015-04-15 19:21:00 +0000288 'available' : available
289 };
290
Nils Diewald7c8ced22015-04-15 19:21:00 +0000291 it('should be initializable by Object', function () {
292 expect(function() {
Akron671fdb92017-09-12 18:09:46 +0200293 matchClass.create()
Nils Diewald7c8ced22015-04-15 19:21:00 +0000294 }).toThrow(new Error('Missing parameters'));
295
296 expect(matchClass.create(match)).toBeTruthy();
297
298 var m = matchClass.create(match);
Akron0a6768f2016-07-13 18:00:43 +0200299 expect(m.textSigle).toEqual("WPD/UUU/01912");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000300 expect(m.matchID).toEqual("p121-122");
301
302 // /corpus/WPD/UUU.01912/p121-122/matchInfo?spans=false&foundry=*
303 var m = matchClass.create(match);
304
305 // Spans:
306 var spans = m.getSpans();
307 expect(spans[0].foundry).toEqual("base");
308 expect(spans[0].layer).toEqual("s");
309
310 expect(spans[1].foundry).toEqual("corenlp");
311 expect(spans[1].layer).toEqual("c");
312
313 expect(spans[2].foundry).toEqual("corenlp");
314 expect(spans[2].layer).toEqual("s");
315
316 expect(spans[spans.length-1].foundry).toEqual("tt");
317 expect(spans[spans.length-1].layer).toEqual("s");
318
319 // Tokens:
320 var tokens = m.getTokens();
321 expect(tokens[0].foundry).toEqual("corenlp");
322 expect(tokens[0].layer).toEqual("ne");
323
324 expect(tokens[1].foundry).toEqual("corenlp");
325 expect(tokens[1].layer).toEqual("p");
326
327 expect(tokens[tokens.length-1].foundry).toEqual("tt");
328 expect(tokens[tokens.length-1].layer).toEqual("p");
Nils Diewald58141332015-04-07 16:18:45 +0000329 });
Nils Diewalda297f062015-04-02 00:23:46 +0000330
331
Akroncdb0baa2016-11-07 01:52:11 +0100332 it('should be initializable by Node 1', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000333 var m = matchClass.create(matchElementFactory());
Akron0a6768f2016-07-13 18:00:43 +0200334 expect(m.textSigle).toEqual("WPD/FFF/01460");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000335 expect(m.matchID).toEqual("p119-120");
Nils Diewalda297f062015-04-02 00:23:46 +0000336
Nils Diewald7c8ced22015-04-15 19:21:00 +0000337 // Spans:
338 var spans = m.getSpans();
339 expect(spans[0].foundry).toEqual("base");
340 expect(spans[0].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000341
Nils Diewald7c8ced22015-04-15 19:21:00 +0000342 expect(spans[1].foundry).toEqual("corenlp");
343 expect(spans[1].layer).toEqual("c");
Nils Diewalda297f062015-04-02 00:23:46 +0000344
Nils Diewald7c8ced22015-04-15 19:21:00 +0000345 expect(spans[2].foundry).toEqual("corenlp");
346 expect(spans[2].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000347
Nils Diewald7c8ced22015-04-15 19:21:00 +0000348 expect(spans[spans.length-1].foundry).toEqual("tt");
349 expect(spans[spans.length-1].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000350
Nils Diewald7c8ced22015-04-15 19:21:00 +0000351 // Tokens:
352 var tokens = m.getTokens();
353 expect(tokens[0].foundry).toEqual("corenlp");
354 expect(tokens[0].layer).toEqual("ne");
Nils Diewalda297f062015-04-02 00:23:46 +0000355
Nils Diewald7c8ced22015-04-15 19:21:00 +0000356 expect(tokens[1].foundry).toEqual("corenlp");
357 expect(tokens[1].layer).toEqual("p");
Nils Diewalda297f062015-04-02 00:23:46 +0000358
Nils Diewald7c8ced22015-04-15 19:21:00 +0000359 expect(tokens[tokens.length-1].foundry).toEqual("tt");
360 expect(tokens[tokens.length-1].layer).toEqual("p");
Nils Diewalda297f062015-04-02 00:23:46 +0000361
Nils Diewald7c8ced22015-04-15 19:21:00 +0000362 });
Nils Diewalda297f062015-04-02 00:23:46 +0000363
Akroncdb0baa2016-11-07 01:52:11 +0100364 it('should be initializable by Node 2', function () {
365 var ele = matchElementReal();
366 var m = matchClass.create(ele);
367 expect(m.textSigle).toEqual("GOE/AGI/00000");
368 expect(m.matchID).toEqual("p85183-85184");
369 });
370
371
Nils Diewald7c8ced22015-04-15 19:21:00 +0000372 it('should react to gui actions', function () {
373 var e = matchElementFactory();
Nils Diewalda297f062015-04-02 00:23:46 +0000374
Nils Diewald7c8ced22015-04-15 19:21:00 +0000375 expect(e.classList.contains('active')).toBe(false);
376 expect(e["_match"]).toBe(undefined);
Nils Diewalda297f062015-04-02 00:23:46 +0000377
Nils Diewald7c8ced22015-04-15 19:21:00 +0000378 var m = matchClass.create(e);
379
380 expect(e.classList.contains('active')).toBe(false);
381 expect(e["_match"]).not.toBe(undefined);
382
383 // Open the match
384 m.open();
385
386 expect(e.classList.contains('active')).toBe(true);
387 expect(e["_match"]).not.toBe(undefined);
388
Akronbfe912c2018-07-17 19:30:52 +0200389 actions = e.querySelector("p.ref > div.action.button-group").children;
Akrond141a362018-07-10 18:12:13 +0200390
Akronbfe912c2018-07-17 19:30:52 +0200391 expect(actions[0].getAttribute("class")).toEqual("metatable");
Akronc296ca22018-04-24 16:35:26 +0200392 expect(actions[1].getAttribute("class")).toEqual("info");
393 expect(actions[2].getAttribute("class")).toEqual("tree");
394
Nils Diewald7c8ced22015-04-15 19:21:00 +0000395 // Close the match
Akronec6bb8e2018-08-29 13:07:56 +0200396 m.minimize();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000397 expect(e.classList.contains('active')).toBe(false);
398 expect(e["_match"]).not.toBe(undefined);
Nils Diewald58141332015-04-07 16:18:45 +0000399 });
Nils Diewalda297f062015-04-02 00:23:46 +0000400
Akrond8692de2018-07-26 13:06:01 +0200401 it('should open tree menu', function () {
Akronc296ca22018-04-24 16:35:26 +0200402 var e = matchElementFactory();
403 var m = matchClass.create(e);
404 m.open();
Akronbfe912c2018-07-17 19:30:52 +0200405 var relation = e.querySelector("p.ref > div.action.button-group > span:nth-of-type(3)");
Akronc296ca22018-04-24 16:35:26 +0200406 expect(relation.getAttribute("class")).toEqual("tree");
Akron52ed22d2018-07-11 17:05:19 +0200407 expect(document.getElementsByClassName("button-group-list").length).toEqual(0);
Akronc296ca22018-04-24 16:35:26 +0200408
409 expect(document.activeElement.tagName).toEqual("BODY");
410
411 // Show menu
412 relation.click();
Akron52ed22d2018-07-11 17:05:19 +0200413 expect(document.getElementsByClassName("button-group-list").length).toEqual(1);
Akronc296ca22018-04-24 16:35:26 +0200414
415 expect(document.activeElement.tagName).toEqual("UL");
416
417 // Choose first tree
Akron52ed22d2018-07-11 17:05:19 +0200418 document.getElementsByClassName("button-group-list")[0].getElementsByTagName("li")[1].click();
Akronc296ca22018-04-24 16:35:26 +0200419 expect(e.querySelector("div.matchinfo div.matchtree h6 span").innerText).toEqual("corenlp");
420
421 // This should blur the focus
422 expect(document.activeElement.tagName).toEqual("BODY");
423 });
424
425 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000426
Akron7f9a6a32018-07-18 15:05:23 +0200427 describe('KorAP.TableView', function () {
Akrond8692de2018-07-26 13:06:01 +0200428 beforeAll(beforeAllFunc);
429 afterAll(afterAllFunc);
430
Akron7f9a6a32018-07-18 15:05:23 +0200431 var table;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000432
Akron7f9a6a32018-07-18 15:05:23 +0200433 var matchObj = matchClass.create(match);
434 var tableObj = tableClass.create(matchObj);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000435
436 var table1, table2;
437
Nils Diewald7c8ced22015-04-15 19:21:00 +0000438 it('should fail to load a table async', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200439 expect(tableObj).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000440
Akron7f9a6a32018-07-18 15:05:23 +0200441 tableObj.getData([], function (tablen) {
Akron671fdb92017-09-12 18:09:46 +0200442 table1 = tablen;
443 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000444 });
445 });
446
Akron671fdb92017-09-12 18:09:46 +0200447
Akronaeeb8252018-09-19 18:51:00 +0200448 xit('should\'nt be parsable (async)', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000449 expect(table1).not.toBeTruthy();
450 });
451
Nils Diewald7c8ced22015-04-15 19:21:00 +0000452
Nils Diewald7c8ced22015-04-15 19:21:00 +0000453 it('should be retrieved async', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200454 expect(tableObj).toBeTruthy();
455 tableObj.getData(undefined, function (x) {
Akron671fdb92017-09-12 18:09:46 +0200456 table = x;
457 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000458 });
459 });
Nils Diewalda297f062015-04-02 00:23:46 +0000460
Akron7f9a6a32018-07-18 15:05:23 +0200461 it('should parse into a table (async)', function () {
462 expect(table).toBeTruthy();
Akron5b1a6af2018-02-05 15:41:16 +0100463
Akron7f9a6a32018-07-18 15:05:23 +0200464 expect(table.length()).toBe(3);
465
466 expect(table.getToken(0)).toBe("meist");
467 expect(table.getToken(1)).toBe("deutlich");
468 expect(table.getToken(2)).toBe("leistungsfähiger");
469
470 expect(table.getValue(0, "cnx", "p")[0]).toBe("ADV");
471 expect(table.getValue(0, "cnx", "syn")[0]).toBe("@PREMOD");
472 expect(table.getValue(0, "mate", "l")[0]).toBe("meist");
473 expect(table.getValue(0, "mate", "l")[1]).toBeUndefined();
474
475 expect(table.getValue(2, "cnx", "l")[0]).toBe("fähig");
476 expect(table.getValue(2, "cnx", "l")[1]).toBe("leistung");
477 });
478
479 it('should be rendered async', function () {
Akron5b1a6af2018-02-05 15:41:16 +0100480 var e = table.element().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000481 expect(e.nodeName).toBe('TABLE');
482 expect(e.children[0].nodeName).toBe('THEAD');
483 var tr = e.children[0].children[0];
484 expect(tr.nodeName).toBe('TR');
485 expect(tr.children[0].nodeName).toBe('TH');
Nils Diewald58141332015-04-07 16:18:45 +0000486
Nils Diewald7c8ced22015-04-15 19:21:00 +0000487 expect(tr.children[0].firstChild.nodeValue).toBe('Foundry');
488 expect(tr.children[1].firstChild.nodeValue).toBe('Layer');
489 expect(tr.children[2].firstChild.nodeValue).toBe('meist');
Akronad1e46a2018-09-19 15:55:40 +0200490 expect(tr.children[2].classList.contains('mark')).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000491 expect(tr.children[3].firstChild.nodeValue).toBe('deutlich');
Akronad1e46a2018-09-19 15:55:40 +0200492 expect(tr.children[3].classList.contains('mark')).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000493 expect(tr.children[4].firstChild.nodeValue).toBe('leistungsfähiger');
Akronad1e46a2018-09-19 15:55:40 +0200494 expect(tr.children[4].classList.contains('mark')).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000495
496 // first row
497 tr = e.children[1].children[0];
498 expect(tr.nodeName).toBe('TR');
499 expect(tr.getAttribute('tabindex')).toEqual('0');
500 expect(tr.children[0].nodeName).toBe('TH');
501 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
502 expect(tr.children[1].firstChild.nodeValue).toEqual('l');
503 expect(tr.children[2].firstChild.nodeValue).toEqual('meist');
504 expect(tr.children[3].firstChild.nodeValue).toEqual('deutlich');
Akron47774c42017-07-03 20:14:55 +0200505 expect(tr.children[4].firstChild.firstChild.nodeValue).toEqual('fähig');
506 expect(tr.children[4].lastChild.firstChild.nodeValue).toEqual('leistung');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000507
508 // second row
509 tr = e.children[1].children[1];
510 expect(tr.nodeName).toBe('TR');
511 expect(tr.getAttribute('tabindex')).toEqual('0');
512 expect(tr.children[0].nodeName).toBe('TH');
513 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
514 expect(tr.children[1].firstChild.nodeValue).toEqual('p');
515 expect(tr.children[2].firstChild.nodeValue).toEqual('ADV');
516 expect(tr.children[3].firstChild.nodeValue).toEqual('A');
Akron47774c42017-07-03 20:14:55 +0200517 expect(tr.children[4].firstChild.firstChild.nodeValue).toEqual('A');
518 expect(tr.children[4].lastChild.firstChild.nodeValue).toEqual('ADJA');
Akronf2279c42017-12-21 13:48:46 +0100519
520 expect(tr.children[4].firstChild.getAttribute("title")).toEqual('Adjective');
521 expect(tr.children[2].getAttribute("title")).toEqual('Adverb');
522
Nils Diewald58141332015-04-07 16:18:45 +0000523 });
Akron7f9a6a32018-07-18 15:05:23 +0200524
525
526 it('should parse into a table view (sync)', function () {
527 var matchElement = matchElementFactory();
528 expect(matchElement.tagName).toEqual('LI');
529
530 // Match
531 expect(matchElement.children[0].tagName).toEqual('DIV');
532
533 // snippet
534 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
535 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
536 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
537
538 // reference
539 expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
540 expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
541
542 // not yet
543 expect(matchElement.children[0].children[1]).toBe(undefined);
544
545 /*
546 var info = matchClass.create(matchElement).info();
547 info.showTable();
548 */
549 var matchObj = matchClass.create(matchElement);
550 matchObj.open();
551
552 // Match
553 expect(matchElement.children[0].tagName).toEqual('DIV');
554
555 // snippet
556 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
557
558 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
559
560 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
561
562 // reference
563
564 expect(matchElement.children[2].classList.contains('ref')).toBeTruthy();
565 expect(matchElement.children[2].childNodes[1].nodeValue).toEqual('me');
566
567 // Add table
568 matchObj.panel.addTable();
569
570 // now
571 var infotable = matchElement.children[1];
572 expect(infotable.tagName).toEqual('DIV');
573
574 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
575
576 expect(infotable.firstChild.firstChild.firstChild.classList.contains('matchtable')).toBeTruthy();
577
578 // expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
579 });
580
Nils Diewald58141332015-04-07 16:18:45 +0000581 });
Nils Diewalda297f062015-04-02 00:23:46 +0000582
Akron7f9a6a32018-07-18 15:05:23 +0200583 describe('KorAP.RelationsView', function () {
Akrond8692de2018-07-26 13:06:01 +0200584 beforeAll(beforeAllFunc);
585 afterAll(afterAllFunc);
586
Nils Diewald7c8ced22015-04-15 19:21:00 +0000587 var tree;
Nils Diewalda297f062015-04-02 00:23:46 +0000588
Nils Diewald7c8ced22015-04-15 19:21:00 +0000589 it('should be rendered async 1', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200590 var matchObj = matchClass.create(match);
591 var relObj = relClass.create(matchObj);
592 expect(relObj).toBeTruthy();
593 relObj.getData(undefined, undefined, "spans", function (y) {
Akron671fdb92017-09-12 18:09:46 +0200594 tree = y;
595 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000596 });
597 });
Nils Diewalda297f062015-04-02 00:23:46 +0000598
Nils Diewald7c8ced22015-04-15 19:21:00 +0000599 it('should be rendered async 2', function () {
Akron7f9a6a32018-07-18 15:05:23 +0200600 expect(tree).toBeTruthy();
601 expect(tree.nodes()).toEqual(49);
602
Nils Diewald7c8ced22015-04-15 19:21:00 +0000603 var e = tree.element();
604 expect(e.nodeName).toEqual('svg');
605 expect(e.getElementsByTagName('g').length).toEqual(48);
Nils Diewald58141332015-04-07 16:18:45 +0000606 });
Akron7f9a6a32018-07-18 15:05:23 +0200607
608
609 it('should add a tree view async 2', function () {
610 var matchElement = matchElementFactory();
611 var matchObj = matchClass.create(matchElement);
612 matchObj.open();
613 matchObj.panel.addTree('mate', 'beebop', 'spans', function () {
614 done();
615 });
616
617 // With added tree
618 var tree = matchElement.children[1].firstChild.firstChild.firstChild;
619 expect(tree.tagName).toEqual('DIV');
620 expect(tree.classList.contains('matchtree')).toBeTruthy();
621 expect(tree.children[0].tagName).toEqual('H6');
622 expect(tree.children[0].children[0].tagName).toEqual('SPAN');
623 expect(tree.children[0].children[0].firstChild.nodeValue).toEqual('mate');
624 expect(tree.children[0].children[1].tagName).toEqual('SPAN');
625 expect(tree.children[0].children[1].firstChild.nodeValue).toEqual('beebop');
626
627 expect(tree.children[1].tagName).toEqual('DIV');
628 });
629
Nils Diewald58141332015-04-07 16:18:45 +0000630 });
Nils Diewalda297f062015-04-02 00:23:46 +0000631
Nils Diewald7c8ced22015-04-15 19:21:00 +0000632
633 describe('KorAP.MatchTreeItem', function () {
Akrond8692de2018-07-26 13:06:01 +0200634 beforeAll(beforeAllFunc);
635 afterAll(afterAllFunc);
636
Nils Diewald7c8ced22015-04-15 19:21:00 +0000637 it('should be initializable', function () {
638 var mi = matchTreeItemClass.create(['cnx/c', 'cnx', 'c'])
639 expect(mi.element().firstChild.nodeValue).toEqual('cnx/c');
640 expect(mi.lcField()).toEqual(' cnx/c');
641 expect(mi.foundry()).toEqual('cnx');
642 expect(mi.layer()).toEqual('c');
643 });
Nils Diewalda297f062015-04-02 00:23:46 +0000644 });
Nils Diewalda297f062015-04-02 00:23:46 +0000645
646
Akron671fdb92017-09-12 18:09:46 +0200647 describe('KorAP.MatchRelation', function () {
Akrond8692de2018-07-26 13:06:01 +0200648 beforeAll(beforeAllFunc);
649 afterAll(afterAllFunc);
Akron671fdb92017-09-12 18:09:46 +0200650
651 var relExample = "<span class=\"context-left\"></span>" +
652 "<span class=\"match\">" +
653 " <span xml:id=\"token-GOE/AGA/01784-p199\">" +
654 " <span xlink:title=\"malt/d:ADV\" " +
655 " xlink:type=\"simple\" " +
656 " xlink:href=\"#token-GOE/AGA/01784-p199\">dann</span>" +
657 " </span>" +
658 " zog " +
659 " <span xlink:title=\"malt/d:SUBJ\" " +
660 " xlink:type=\"simple\" " +
661 " xlink:href=\"#token-GOE/AGA/01784-p199\">ich</span>" +
662 " <span xml:id=\"token-GOE/AGA/01784-p202\">" +
663 " <span xlink:title=\"malt/d:OBJA\" " +
664 " xlink:type=\"simple\" " +
665 " xlink:href=\"#token-GOE/AGA/01784-p199\">mich</span>" +
666 " </span>" +
667 "</span>" +
668 "<span class=\"context-right\"></span>";
669
670
671 it('should be initializable', function () {
Akrond8692de2018-07-26 13:06:01 +0200672 var tree = matchRelClass.create();
Akron671fdb92017-09-12 18:09:46 +0200673 expect(tree.size()).toBe(0);
674 });
675
676 it('should be parse string data', function () {
Akrond8692de2018-07-26 13:06:01 +0200677 var tree = matchRelClass.create(relExample);
Akron671fdb92017-09-12 18:09:46 +0200678 expect(tree.size()).toBe(4);
679 });
Akron671fdb92017-09-12 18:09:46 +0200680 });
681
682
Nils Diewald7c8ced22015-04-15 19:21:00 +0000683 describe('KorAP.MatchTreeMenu', function () {
Akrond8692de2018-07-26 13:06:01 +0200684 beforeAll(beforeAllFunc);
685 afterAll(afterAllFunc);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000686
687 it('should be initializable', function () {
Akrond8692de2018-07-26 13:06:01 +0200688 var menu = matchTreeMenuClass.create([
Akron671fdb92017-09-12 18:09:46 +0200689 ['cnx/c', 'cnx', 'c'],
690 ['xip/c', 'xip', 'c']
Akrond8692de2018-07-26 13:06:01 +0200691 ], matchTreeItemClass);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000692
Akrond8692de2018-07-26 13:06:01 +0200693 expect(menu.itemClass()).toEqual(matchTreeItemClass);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000694 expect(menu.element().nodeName).toEqual('UL');
Akronaba7a5a2016-08-15 21:58:33 +0200695 expect(menu.element().classList.contains('visible')).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000696 expect(menu.limit()).toEqual(6);
697 menu.show();
Akronaba7a5a2016-08-15 21:58:33 +0200698 expect(menu.element().classList.contains('visible')).toBeTruthy();
Akronc1457bf2015-06-11 19:24:00 +0200699 expect(menu.item(0).active()).toBe(false);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000700 });
Nils Diewalda297f062015-04-02 00:23:46 +0000701 });
hebasta999d6c12018-04-23 12:44:59 +0200702
703 //Test display and sorting of meta information
704 describe('KorAP.Meta', function(){
Akrond8692de2018-07-26 13:06:01 +0200705 beforeAll(beforeAllFunc);
706 afterAll(afterAllFunc);
707
708 var met = metaClass.create(match, fields);
hebasta999d6c12018-04-23 12:44:59 +0200709 var mel = met.element();
710
711 // Meta information should be parsed into a list
712 it('should parse in a meta view', function(){
Akronfa32c9d2018-11-20 15:39:18 +0100713 expect(mel.tagName).toEqual('DL');
714 expect(mel.children[0].tagName).toEqual('DIV');
715 expect(mel.children[0].children[0].tagName).toEqual('DT');
716 expect(mel.children[0].children[0].attributes[0].name).toEqual('title');
717 expect(mel.children[0].children[1].tagName).toEqual('DD');
718 expect(mel.children[0].children[1].getAttribute('data-type')).toEqual('type:text')
hebasta999d6c12018-04-23 12:44:59 +0200719
Akronfa32c9d2018-11-20 15:39:18 +0100720 expect(mel.children[0].children[0].firstChild.nodeValue).toEqual('author');
721 expect(mel.children[0].children[1].firstChild.nodeValue).toEqual('Sprachpfleger, u.a.');
722 expect(mel.children[0].children[0].attributes[0].value).toEqual('author');
hebasta999d6c12018-04-23 12:44:59 +0200723 });
724
725
Akronfa32c9d2018-11-20 15:39:18 +0100726 /* The keywords in the meta information list should be formatted to be able
727 to chose each keyword separately in the corpusByMatch assistant. */
728 it('keywords should be formatted', function(){
hebasta999d6c12018-04-23 12:44:59 +0200729
Akronfa32c9d2018-11-20 15:39:18 +0100730 //type:string or type:keyword should b not relevant
731 expect(mel.children[1].children[1].getAttribute('data-type')).toEqual('type:string')
732 expect(mel.children[1].children[1].classList.contains('metakeyvalues')).toBeTruthy;
733 expect(mel.children[1].children[1].children[0].tagName).toEqual('DIV');
734 expect(mel.children[1].children[1].children[0].firstChild.nodeValue).toEqual('corenlp');
735 expect(mel.children[1].children[1].children[1].tagName).toEqual('DIV');
736 expect(mel.children[1].children[1].children[1].firstChild.nodeValue).toEqual('corenlp\/constituency');
737
738 expect(mel.children[2].children[1].classList.contains('metakeyvalues')).toBeTruthy;
739 expect(mel.children[2].children[1].children[0].tagName).toEqual('DIV');
740 expect(mel.children[2].children[1].children[0].firstChild.nodeValue).toEqual('kultur');
741 expect(mel.children[2].children[1].children[1].tagName).toEqual('DIV');
742 expect(mel.children[2].children[1].children[1].firstChild.nodeValue).toEqual('film');
hebasta999d6c12018-04-23 12:44:59 +0200743 });
744
745
Akronfa32c9d2018-11-20 15:39:18 +0100746 // Meta information should be sorted alphabetically
747 it('should be alphabetically sorted', function(){
748 var a = mel.children[0].children[0].firstChild.nodeValue;
749 var b = mel.children[1].children[0].firstChild.nodeValue;
750 var c = mel.children[2].children[0].firstChild.nodeValue;
751 expect(a.localeCompare(b)).toBe(-1);
752 expect(b.localeCompare(c)).toBe(-1);
753 });
hebasta999d6c12018-04-23 12:44:59 +0200754 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000755 // table = view.toTable();
756 // table.sortBy('');
757 // table.element();
758 // tree = view.toTree();
759 // tree.element();
Nils Diewalda297f062015-04-02 00:23:46 +0000760});