blob: b72cd9a5c16f472a7e5cd37dbf805d609ff008bc [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",
61 "type": "type:keywords",
62 "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>" +
97 "<span title=\"cnx/l:deutlich\">" +
98 " <span title=\"cnx/p:A\">" +
99 " <span title=\"cnx/syn:@PREMOD\">" +
100 " <span title=\"mate/l:deutlich\">" +
101 " <span title=\"mate/m:degree:pos\">" +
102 " <span title=\"mate/p:ADJD\">" +
103 " <span title=\"opennlp/p:ADJD\">deutlich</span>" +
104 " </span>" +
105 " </span>" +
106 " </span>" +
107 " </span>" +
108 " </span>" +
109 "</span>" +
110 "<span title=\"cnx/l:fähig\">" +
111 " <span title=\"cnx/l:leistung\">" +
112 " <span title=\"cnx/p:A\">" +
113 " <span title=\"cnx/p:ADJA\">" +
114 " <span title=\"cnx/syn:@NH\">" +
115 " <span title=\"mate/l:leistungsfähig\">" +
116 " <span title=\"mate/m:degree:comp\">" +
117 " <span title=\"mate/p:ADJD\">" +
118 " <span title=\"opennlp/p:ADJD\">leistungsfähiger</span>" +
119 " </span>" +
120 " </span>" +
121 " </span>" +
122 " </span>" +
123 " </span>" +
124 " </span>" +
125 " </span>" +
126 "</span>";
127
128 var treeSnippet =
129 "<span class=\"context-left\"></span>" +
130 "<span class=\"match\">" +
131 " <span title=\"xip/c:MC\">" +
132 " <span title=\"xip/c:TOP\">" +
133 " <span title=\"xip/c:PP\">" +
134 " <span title=\"xip/c:PREP\">Mit</span>" +
135 " <span title=\"xip/c:NP\">" +
136 " <span title=\"xip/c:DET\">dieser</span>" +
137 " <span title=\"xip/c:NPA\">" +
138 " <span title=\"xip/c:NOUN\">Methode</span>" +
139 " </span>" +
140 " </span>" +
141 " </span>" +
142 " <span title=\"xip/c:VERB\">ist</span>" +
143 " <mark>" +
144 " <span title=\"xip/c:NP\">" +
145 " <span title=\"xip/c:PRON\">es</span>" +
146 " </span>" +
147 " <span title=\"xip/c:AP\">" +
148 " <span title=\"xip/c:ADV\">nun</span>" +
149 " <span title=\"xip/c:ADJ\">möglich</span>" +
150 " </span>" +
151 " </mark>" +
152 " <span title=\"xip/c:ADV\">z. B.</span>" +
153 " <span title=\"xip/c:NPA\">" +
154 " <span title=\"xip/c:NP\">" +
155 " <span title=\"xip/c:NOUN\">Voice</span>" +
156 " </span>" +
157 " </span>" + "(" +
158 " <span title=\"xip/c:INS\">" +
159 " <span title=\"xip/c:NPA\">" +
160 " <span title=\"xip/c:NP\">" +
161 " <span title=\"xip/c:NOUN\">Sprache</span>" +
162 " </span>" +
163 " </span>" +
164 " </span>" + ")" +
165 " <span title=\"xip/c:VERB\">bevorzugt</span>" +
166 " <span title=\"xip/c:PP\">" +
167 " <span title=\"xip/c:PREP\">in</span>" +
168 " <span title=\"xip/c:NP\">" +
169 " <span title=\"xip/c:PRON\">der</span>" +
170 " </span>" +
171 " <span title=\"xip/c:NPA\">" +
172 " <span title=\"xip/c:NP\">" +
173 " <span title=\"xip/c:NOUN\">Bridge</span>" +
174 " </span>" +
175 " </span>" +
176 " </span>" +
177 " <span title=\"xip/c:INFC\">" +
178 " <span title=\"xip/c:INS\">" +
179 " <span title=\"xip/c:VERB\">weiterzugeben</span>" +
180 " </span>" +
181 " </span>" +
182 " </span>" +
183 " </span>" +
184 "</span>" +
185 "<span class=\"context-right\"></span>";
186
187
188 function matchElementFactory () {
189 var me = document.createElement('li');
190
191 me.setAttribute(
192 'data-available-info',
193 'base/s=spans corenlp/c=spans corenlp/ne=tokens corenlp/p=tokens' +
194 ' corenlp/s=spans glemm/l=tokens mate/l=tokens mate/m=tokens' +
195 ' mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens' +
196 ' tt/p=tokens tt/s=spans');
197
198 me.setAttribute('data-corpus-id', 'WPD');
199 me.setAttribute('data-doc-id', 'FFF');
200 me.setAttribute('data-text-id', '01460');
201 me.setAttribute('data-text-sigle', 'WPD/FFF/01460');
202 me.setAttribute('data-match-id', 'p119-120');
203 me.innerHTML = '<div><div class="snippet">check</div></div><p class="ref">me</p>';
204 return me;
205 };
206
207 function matchElementReal () {
208 var me = document.createElement('em');
209 me.innerHTML =
210 '<li data-match-id="p85183-85184"' +
211 ' data-text-sigle="GOE/AGI/00000"' +
212 ' 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"' +
213 ' 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;}"' +
214 ' id="GOE/AGI/00000#p85183-85184">' +
215 '<div>' +
216 '<div class="flag"></div>' +
217 '<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>' +
218 '</div>' +
219 '<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>' +
220 '</li>';
221 return me.firstChild;
222 };
223
224 var beforeAllFunc = function () {
225 // Override getMatchInfo API call
226 KorAP.API.getMatchInfo = function (x, param, cb) {
227 if (param['spans'] === undefined || param['spans'] === false)
228 cb({ "snippet": snippet });
229 else
230 cb({ "snippet": treeSnippet });
231 };
232 };
233
234 var afterAllFunc = function () {
235 KorAP.API.getMatchInfo = undefined;
236 // KorAP.annotationHelper = undefined;
237 var body = document.body;
238 for (var i in body.children) {
239 if (body.children[i].nodeType && body.children[i].nodeType === 1) {
240 if (!body.children[i].classList.contains("jasmine_html-reporter")) {
241 body.removeChild(body.children[i]);
242 };
243 };
244 };
245 };
246
Akron671fdb92017-09-12 18:09:46 +0200247
Nils Diewald7c8ced22015-04-15 19:21:00 +0000248 describe('KorAP.InfoLayer', function () {
Akrond8692de2018-07-26 13:06:01 +0200249 beforeAll(beforeAllFunc);
250 afterAll(afterAllFunc);
Nils Diewalda297f062015-04-02 00:23:46 +0000251
Nils Diewald7c8ced22015-04-15 19:21:00 +0000252 it('should be initializable', function () {
253 expect(
Akron671fdb92017-09-12 18:09:46 +0200254 function() { infoClass.create() }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000255 ).toThrow(new Error("Missing parameters"));
Nils Diewalda297f062015-04-02 00:23:46 +0000256
Nils Diewald7c8ced22015-04-15 19:21:00 +0000257 expect(
Akron671fdb92017-09-12 18:09:46 +0200258 function() { infoClass.create("base") }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000259 ).toThrow(new Error("Missing parameters"));
Nils Diewalda297f062015-04-02 00:23:46 +0000260
Nils Diewald7c8ced22015-04-15 19:21:00 +0000261 var layer = infoClass.create("base", "s");
262 expect(layer).toBeTruthy();
263 expect(layer.foundry).toEqual("base");
264 expect(layer.layer).toEqual("s");
265 expect(layer.type).toEqual("tokens");
Nils Diewalda297f062015-04-02 00:23:46 +0000266
Nils Diewald7c8ced22015-04-15 19:21:00 +0000267 layer = infoClass.create("cnx", "syn", "spans");
268 expect(layer).toBeTruthy();
269 expect(layer.foundry).toEqual("cnx");
270 expect(layer.layer).toEqual("syn");
271 expect(layer.type).toEqual("spans");
Nils Diewald58141332015-04-07 16:18:45 +0000272 });
273 });
Nils Diewalda297f062015-04-02 00:23:46 +0000274
Nils Diewalda297f062015-04-02 00:23:46 +0000275
Nils Diewald7c8ced22015-04-15 19:21:00 +0000276 describe('KorAP.Match', function () {
Akrond8692de2018-07-26 13:06:01 +0200277 beforeAll(beforeAllFunc);
278 afterAll(afterAllFunc);
279
Nils Diewald7c8ced22015-04-15 19:21:00 +0000280 var match = {
281 'corpusID' : 'WPD',
282 'docID' : 'UUU',
283 'textID' : '01912',
284 'matchID' : 'p121-122',
Akron0a6768f2016-07-13 18:00:43 +0200285 'textSigle' : 'WPD/UUU/01912',
Nils Diewald7c8ced22015-04-15 19:21:00 +0000286 'available' : available
287 };
288
Nils Diewald7c8ced22015-04-15 19:21:00 +0000289 it('should be initializable by Object', function () {
290 expect(function() {
Akron671fdb92017-09-12 18:09:46 +0200291 matchClass.create()
Nils Diewald7c8ced22015-04-15 19:21:00 +0000292 }).toThrow(new Error('Missing parameters'));
293
294 expect(matchClass.create(match)).toBeTruthy();
295
296 var m = matchClass.create(match);
Akron0a6768f2016-07-13 18:00:43 +0200297 expect(m.textSigle).toEqual("WPD/UUU/01912");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000298 expect(m.matchID).toEqual("p121-122");
299
300 // /corpus/WPD/UUU.01912/p121-122/matchInfo?spans=false&foundry=*
301 var m = matchClass.create(match);
302
303 // Spans:
304 var spans = m.getSpans();
305 expect(spans[0].foundry).toEqual("base");
306 expect(spans[0].layer).toEqual("s");
307
308 expect(spans[1].foundry).toEqual("corenlp");
309 expect(spans[1].layer).toEqual("c");
310
311 expect(spans[2].foundry).toEqual("corenlp");
312 expect(spans[2].layer).toEqual("s");
313
314 expect(spans[spans.length-1].foundry).toEqual("tt");
315 expect(spans[spans.length-1].layer).toEqual("s");
316
317 // Tokens:
318 var tokens = m.getTokens();
319 expect(tokens[0].foundry).toEqual("corenlp");
320 expect(tokens[0].layer).toEqual("ne");
321
322 expect(tokens[1].foundry).toEqual("corenlp");
323 expect(tokens[1].layer).toEqual("p");
324
325 expect(tokens[tokens.length-1].foundry).toEqual("tt");
326 expect(tokens[tokens.length-1].layer).toEqual("p");
Nils Diewald58141332015-04-07 16:18:45 +0000327 });
Nils Diewalda297f062015-04-02 00:23:46 +0000328
329
Akroncdb0baa2016-11-07 01:52:11 +0100330 it('should be initializable by Node 1', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000331 var m = matchClass.create(matchElementFactory());
Akron0a6768f2016-07-13 18:00:43 +0200332 expect(m.textSigle).toEqual("WPD/FFF/01460");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000333 expect(m.matchID).toEqual("p119-120");
Nils Diewalda297f062015-04-02 00:23:46 +0000334
Nils Diewald7c8ced22015-04-15 19:21:00 +0000335 // Spans:
336 var spans = m.getSpans();
337 expect(spans[0].foundry).toEqual("base");
338 expect(spans[0].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000339
Nils Diewald7c8ced22015-04-15 19:21:00 +0000340 expect(spans[1].foundry).toEqual("corenlp");
341 expect(spans[1].layer).toEqual("c");
Nils Diewalda297f062015-04-02 00:23:46 +0000342
Nils Diewald7c8ced22015-04-15 19:21:00 +0000343 expect(spans[2].foundry).toEqual("corenlp");
344 expect(spans[2].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000345
Nils Diewald7c8ced22015-04-15 19:21:00 +0000346 expect(spans[spans.length-1].foundry).toEqual("tt");
347 expect(spans[spans.length-1].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000348
Nils Diewald7c8ced22015-04-15 19:21:00 +0000349 // Tokens:
350 var tokens = m.getTokens();
351 expect(tokens[0].foundry).toEqual("corenlp");
352 expect(tokens[0].layer).toEqual("ne");
Nils Diewalda297f062015-04-02 00:23:46 +0000353
Nils Diewald7c8ced22015-04-15 19:21:00 +0000354 expect(tokens[1].foundry).toEqual("corenlp");
355 expect(tokens[1].layer).toEqual("p");
Nils Diewalda297f062015-04-02 00:23:46 +0000356
Nils Diewald7c8ced22015-04-15 19:21:00 +0000357 expect(tokens[tokens.length-1].foundry).toEqual("tt");
358 expect(tokens[tokens.length-1].layer).toEqual("p");
Nils Diewalda297f062015-04-02 00:23:46 +0000359
Nils Diewald7c8ced22015-04-15 19:21:00 +0000360 });
Nils Diewalda297f062015-04-02 00:23:46 +0000361
Akroncdb0baa2016-11-07 01:52:11 +0100362 it('should be initializable by Node 2', function () {
363 var ele = matchElementReal();
364 var m = matchClass.create(ele);
365 expect(m.textSigle).toEqual("GOE/AGI/00000");
366 expect(m.matchID).toEqual("p85183-85184");
367 });
368
369
Nils Diewald7c8ced22015-04-15 19:21:00 +0000370 it('should react to gui actions', function () {
371 var e = matchElementFactory();
Nils Diewalda297f062015-04-02 00:23:46 +0000372
Nils Diewald7c8ced22015-04-15 19:21:00 +0000373 expect(e.classList.contains('active')).toBe(false);
374 expect(e["_match"]).toBe(undefined);
Nils Diewalda297f062015-04-02 00:23:46 +0000375
Nils Diewald7c8ced22015-04-15 19:21:00 +0000376 var m = matchClass.create(e);
377
378 expect(e.classList.contains('active')).toBe(false);
379 expect(e["_match"]).not.toBe(undefined);
380
381 // Open the match
382 m.open();
383
384 expect(e.classList.contains('active')).toBe(true);
385 expect(e["_match"]).not.toBe(undefined);
386
Akronbfe912c2018-07-17 19:30:52 +0200387 actions = e.querySelector("p.ref > div.action.button-group").children;
Akrond141a362018-07-10 18:12:13 +0200388
Akronbfe912c2018-07-17 19:30:52 +0200389 expect(actions[0].getAttribute("class")).toEqual("metatable");
Akronc296ca22018-04-24 16:35:26 +0200390 expect(actions[1].getAttribute("class")).toEqual("info");
391 expect(actions[2].getAttribute("class")).toEqual("tree");
392
Nils Diewald7c8ced22015-04-15 19:21:00 +0000393 // Close the match
394 m.close();
395 expect(e.classList.contains('active')).toBe(false);
396 expect(e["_match"]).not.toBe(undefined);
Nils Diewald58141332015-04-07 16:18:45 +0000397 });
Nils Diewalda297f062015-04-02 00:23:46 +0000398
Akrond8692de2018-07-26 13:06:01 +0200399 it('should open tree menu', function () {
Akronc296ca22018-04-24 16:35:26 +0200400 var e = matchElementFactory();
401 var m = matchClass.create(e);
402 m.open();
Akronbfe912c2018-07-17 19:30:52 +0200403 var relation = e.querySelector("p.ref > div.action.button-group > span:nth-of-type(3)");
Akronc296ca22018-04-24 16:35:26 +0200404 expect(relation.getAttribute("class")).toEqual("tree");
Akron52ed22d2018-07-11 17:05:19 +0200405 expect(document.getElementsByClassName("button-group-list").length).toEqual(0);
Akronc296ca22018-04-24 16:35:26 +0200406
407 expect(document.activeElement.tagName).toEqual("BODY");
408
409 // Show menu
410 relation.click();
Akron52ed22d2018-07-11 17:05:19 +0200411 expect(document.getElementsByClassName("button-group-list").length).toEqual(1);
Akronc296ca22018-04-24 16:35:26 +0200412
413 expect(document.activeElement.tagName).toEqual("UL");
414
415 // Choose first tree
Akron52ed22d2018-07-11 17:05:19 +0200416 document.getElementsByClassName("button-group-list")[0].getElementsByTagName("li")[1].click();
Akronc296ca22018-04-24 16:35:26 +0200417 expect(e.querySelector("div.matchinfo div.matchtree h6 span").innerText).toEqual("corenlp");
418
419 // This should blur the focus
420 expect(document.activeElement.tagName).toEqual("BODY");
421 });
422
423 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000424
Akron7f9a6a32018-07-18 15:05:23 +0200425 describe('KorAP.TableView', function () {
Akrond8692de2018-07-26 13:06:01 +0200426 beforeAll(beforeAllFunc);
427 afterAll(afterAllFunc);
428
Akron7f9a6a32018-07-18 15:05:23 +0200429 var table;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000430
Akron7f9a6a32018-07-18 15:05:23 +0200431 var matchObj = matchClass.create(match);
432 var tableObj = tableClass.create(matchObj);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000433
434 var table1, table2;
435
Nils Diewald7c8ced22015-04-15 19:21:00 +0000436 it('should fail to load a table async', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200437 expect(tableObj).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000438
Akron7f9a6a32018-07-18 15:05:23 +0200439 tableObj.getData([], function (tablen) {
Akron671fdb92017-09-12 18:09:46 +0200440 table1 = tablen;
441 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000442 });
443 });
444
Akron671fdb92017-09-12 18:09:46 +0200445
Nils Diewald7c8ced22015-04-15 19:21:00 +0000446 it('should\'nt be parsable (async)', function () {
447 expect(table1).not.toBeTruthy();
448 });
449
Nils Diewald7c8ced22015-04-15 19:21:00 +0000450
Nils Diewald7c8ced22015-04-15 19:21:00 +0000451 it('should be retrieved async', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200452 expect(tableObj).toBeTruthy();
453 tableObj.getData(undefined, function (x) {
Akron671fdb92017-09-12 18:09:46 +0200454 table = x;
455 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000456 });
457 });
Nils Diewalda297f062015-04-02 00:23:46 +0000458
Akron7f9a6a32018-07-18 15:05:23 +0200459 it('should parse into a table (async)', function () {
460 expect(table).toBeTruthy();
Akron5b1a6af2018-02-05 15:41:16 +0100461
Akron7f9a6a32018-07-18 15:05:23 +0200462 expect(table.length()).toBe(3);
463
464 expect(table.getToken(0)).toBe("meist");
465 expect(table.getToken(1)).toBe("deutlich");
466 expect(table.getToken(2)).toBe("leistungsfähiger");
467
468 expect(table.getValue(0, "cnx", "p")[0]).toBe("ADV");
469 expect(table.getValue(0, "cnx", "syn")[0]).toBe("@PREMOD");
470 expect(table.getValue(0, "mate", "l")[0]).toBe("meist");
471 expect(table.getValue(0, "mate", "l")[1]).toBeUndefined();
472
473 expect(table.getValue(2, "cnx", "l")[0]).toBe("fähig");
474 expect(table.getValue(2, "cnx", "l")[1]).toBe("leistung");
475 });
476
477 it('should be rendered async', function () {
Akron5b1a6af2018-02-05 15:41:16 +0100478 var e = table.element().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000479 expect(e.nodeName).toBe('TABLE');
480 expect(e.children[0].nodeName).toBe('THEAD');
481 var tr = e.children[0].children[0];
482 expect(tr.nodeName).toBe('TR');
483 expect(tr.children[0].nodeName).toBe('TH');
Nils Diewald58141332015-04-07 16:18:45 +0000484
Nils Diewald7c8ced22015-04-15 19:21:00 +0000485 expect(tr.children[0].firstChild.nodeValue).toBe('Foundry');
486 expect(tr.children[1].firstChild.nodeValue).toBe('Layer');
487 expect(tr.children[2].firstChild.nodeValue).toBe('meist');
488 expect(tr.children[3].firstChild.nodeValue).toBe('deutlich');
489 expect(tr.children[4].firstChild.nodeValue).toBe('leistungsfähiger');
490
491 // first row
492 tr = e.children[1].children[0];
493 expect(tr.nodeName).toBe('TR');
494 expect(tr.getAttribute('tabindex')).toEqual('0');
495 expect(tr.children[0].nodeName).toBe('TH');
496 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
497 expect(tr.children[1].firstChild.nodeValue).toEqual('l');
498 expect(tr.children[2].firstChild.nodeValue).toEqual('meist');
499 expect(tr.children[3].firstChild.nodeValue).toEqual('deutlich');
Akron47774c42017-07-03 20:14:55 +0200500 expect(tr.children[4].firstChild.firstChild.nodeValue).toEqual('fähig');
501 expect(tr.children[4].lastChild.firstChild.nodeValue).toEqual('leistung');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000502
503 // second row
504 tr = e.children[1].children[1];
505 expect(tr.nodeName).toBe('TR');
506 expect(tr.getAttribute('tabindex')).toEqual('0');
507 expect(tr.children[0].nodeName).toBe('TH');
508 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
509 expect(tr.children[1].firstChild.nodeValue).toEqual('p');
510 expect(tr.children[2].firstChild.nodeValue).toEqual('ADV');
511 expect(tr.children[3].firstChild.nodeValue).toEqual('A');
Akron47774c42017-07-03 20:14:55 +0200512 expect(tr.children[4].firstChild.firstChild.nodeValue).toEqual('A');
513 expect(tr.children[4].lastChild.firstChild.nodeValue).toEqual('ADJA');
Akronf2279c42017-12-21 13:48:46 +0100514
515 expect(tr.children[4].firstChild.getAttribute("title")).toEqual('Adjective');
516 expect(tr.children[2].getAttribute("title")).toEqual('Adverb');
517
Nils Diewald58141332015-04-07 16:18:45 +0000518 });
Akron7f9a6a32018-07-18 15:05:23 +0200519
520
521 it('should parse into a table view (sync)', function () {
522 var matchElement = matchElementFactory();
523 expect(matchElement.tagName).toEqual('LI');
524
525 // Match
526 expect(matchElement.children[0].tagName).toEqual('DIV');
527
528 // snippet
529 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
530 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
531 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
532
533 // reference
534 expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
535 expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
536
537 // not yet
538 expect(matchElement.children[0].children[1]).toBe(undefined);
539
540 /*
541 var info = matchClass.create(matchElement).info();
542 info.showTable();
543 */
544 var matchObj = matchClass.create(matchElement);
545 matchObj.open();
546
547 // Match
548 expect(matchElement.children[0].tagName).toEqual('DIV');
549
550 // snippet
551 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
552
553 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
554
555 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
556
557 // reference
558
559 expect(matchElement.children[2].classList.contains('ref')).toBeTruthy();
560 expect(matchElement.children[2].childNodes[1].nodeValue).toEqual('me');
561
562 // Add table
563 matchObj.panel.addTable();
564
565 // now
566 var infotable = matchElement.children[1];
567 expect(infotable.tagName).toEqual('DIV');
568
569 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
570
571 expect(infotable.firstChild.firstChild.firstChild.classList.contains('matchtable')).toBeTruthy();
572
573 // expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
574 });
575
Nils Diewald58141332015-04-07 16:18:45 +0000576 });
Nils Diewalda297f062015-04-02 00:23:46 +0000577
Akron7f9a6a32018-07-18 15:05:23 +0200578 describe('KorAP.RelationsView', function () {
Akrond8692de2018-07-26 13:06:01 +0200579 beforeAll(beforeAllFunc);
580 afterAll(afterAllFunc);
581
Nils Diewald7c8ced22015-04-15 19:21:00 +0000582 var tree;
Nils Diewalda297f062015-04-02 00:23:46 +0000583
Nils Diewald7c8ced22015-04-15 19:21:00 +0000584 it('should be rendered async 1', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200585 var matchObj = matchClass.create(match);
586 var relObj = relClass.create(matchObj);
587 expect(relObj).toBeTruthy();
588 relObj.getData(undefined, undefined, "spans", function (y) {
Akron671fdb92017-09-12 18:09:46 +0200589 tree = y;
590 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000591 });
592 });
Nils Diewalda297f062015-04-02 00:23:46 +0000593
Nils Diewald7c8ced22015-04-15 19:21:00 +0000594 it('should be rendered async 2', function () {
Akron7f9a6a32018-07-18 15:05:23 +0200595 expect(tree).toBeTruthy();
596 expect(tree.nodes()).toEqual(49);
597
Nils Diewald7c8ced22015-04-15 19:21:00 +0000598 var e = tree.element();
599 expect(e.nodeName).toEqual('svg');
600 expect(e.getElementsByTagName('g').length).toEqual(48);
Nils Diewald58141332015-04-07 16:18:45 +0000601 });
Akron7f9a6a32018-07-18 15:05:23 +0200602
603
604 it('should add a tree view async 2', function () {
605 var matchElement = matchElementFactory();
606 var matchObj = matchClass.create(matchElement);
607 matchObj.open();
608 matchObj.panel.addTree('mate', 'beebop', 'spans', function () {
609 done();
610 });
611
612 // With added tree
613 var tree = matchElement.children[1].firstChild.firstChild.firstChild;
614 expect(tree.tagName).toEqual('DIV');
615 expect(tree.classList.contains('matchtree')).toBeTruthy();
616 expect(tree.children[0].tagName).toEqual('H6');
617 expect(tree.children[0].children[0].tagName).toEqual('SPAN');
618 expect(tree.children[0].children[0].firstChild.nodeValue).toEqual('mate');
619 expect(tree.children[0].children[1].tagName).toEqual('SPAN');
620 expect(tree.children[0].children[1].firstChild.nodeValue).toEqual('beebop');
621
622 expect(tree.children[1].tagName).toEqual('DIV');
623 });
624
Nils Diewald58141332015-04-07 16:18:45 +0000625 });
Nils Diewalda297f062015-04-02 00:23:46 +0000626
Nils Diewald7c8ced22015-04-15 19:21:00 +0000627
628 describe('KorAP.MatchTreeItem', function () {
Akrond8692de2018-07-26 13:06:01 +0200629 beforeAll(beforeAllFunc);
630 afterAll(afterAllFunc);
631
Nils Diewald7c8ced22015-04-15 19:21:00 +0000632 it('should be initializable', function () {
633 var mi = matchTreeItemClass.create(['cnx/c', 'cnx', 'c'])
634 expect(mi.element().firstChild.nodeValue).toEqual('cnx/c');
635 expect(mi.lcField()).toEqual(' cnx/c');
636 expect(mi.foundry()).toEqual('cnx');
637 expect(mi.layer()).toEqual('c');
638 });
Nils Diewalda297f062015-04-02 00:23:46 +0000639 });
Nils Diewalda297f062015-04-02 00:23:46 +0000640
641
Akron671fdb92017-09-12 18:09:46 +0200642 describe('KorAP.MatchRelation', function () {
Akrond8692de2018-07-26 13:06:01 +0200643 beforeAll(beforeAllFunc);
644 afterAll(afterAllFunc);
Akron671fdb92017-09-12 18:09:46 +0200645
646 var relExample = "<span class=\"context-left\"></span>" +
647 "<span class=\"match\">" +
648 " <span xml:id=\"token-GOE/AGA/01784-p199\">" +
649 " <span xlink:title=\"malt/d:ADV\" " +
650 " xlink:type=\"simple\" " +
651 " xlink:href=\"#token-GOE/AGA/01784-p199\">dann</span>" +
652 " </span>" +
653 " zog " +
654 " <span xlink:title=\"malt/d:SUBJ\" " +
655 " xlink:type=\"simple\" " +
656 " xlink:href=\"#token-GOE/AGA/01784-p199\">ich</span>" +
657 " <span xml:id=\"token-GOE/AGA/01784-p202\">" +
658 " <span xlink:title=\"malt/d:OBJA\" " +
659 " xlink:type=\"simple\" " +
660 " xlink:href=\"#token-GOE/AGA/01784-p199\">mich</span>" +
661 " </span>" +
662 "</span>" +
663 "<span class=\"context-right\"></span>";
664
665
666 it('should be initializable', function () {
Akrond8692de2018-07-26 13:06:01 +0200667 var tree = matchRelClass.create();
Akron671fdb92017-09-12 18:09:46 +0200668 expect(tree.size()).toBe(0);
669 });
670
671 it('should be parse string data', function () {
Akrond8692de2018-07-26 13:06:01 +0200672 var tree = matchRelClass.create(relExample);
Akron671fdb92017-09-12 18:09:46 +0200673 expect(tree.size()).toBe(4);
674 });
Akron671fdb92017-09-12 18:09:46 +0200675 });
676
677
Nils Diewald7c8ced22015-04-15 19:21:00 +0000678 describe('KorAP.MatchTreeMenu', function () {
Akrond8692de2018-07-26 13:06:01 +0200679 beforeAll(beforeAllFunc);
680 afterAll(afterAllFunc);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000681
682 it('should be initializable', function () {
Akrond8692de2018-07-26 13:06:01 +0200683 var menu = matchTreeMenuClass.create([
Akron671fdb92017-09-12 18:09:46 +0200684 ['cnx/c', 'cnx', 'c'],
685 ['xip/c', 'xip', 'c']
Akrond8692de2018-07-26 13:06:01 +0200686 ], matchTreeItemClass);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000687
Akrond8692de2018-07-26 13:06:01 +0200688 expect(menu.itemClass()).toEqual(matchTreeItemClass);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000689 expect(menu.element().nodeName).toEqual('UL');
Akronaba7a5a2016-08-15 21:58:33 +0200690 expect(menu.element().classList.contains('visible')).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000691 expect(menu.limit()).toEqual(6);
692 menu.show();
Akronaba7a5a2016-08-15 21:58:33 +0200693 expect(menu.element().classList.contains('visible')).toBeTruthy();
Akronc1457bf2015-06-11 19:24:00 +0200694 expect(menu.item(0).active()).toBe(false);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000695 });
Nils Diewalda297f062015-04-02 00:23:46 +0000696 });
hebasta999d6c12018-04-23 12:44:59 +0200697
698 //Test display and sorting of meta information
699 describe('KorAP.Meta', function(){
Akrond8692de2018-07-26 13:06:01 +0200700 beforeAll(beforeAllFunc);
701 afterAll(afterAllFunc);
702
703 var met = metaClass.create(match, fields);
hebasta999d6c12018-04-23 12:44:59 +0200704 var mel = met.element();
705
706 // Meta information should be parsed into a list
707 it('should parse in a meta view', function(){
708 expect(mel.tagName).toEqual('DL');
709 expect(mel.children[0].tagName).toEqual('DIV');
710 expect(mel.children[0].children[0].tagName).toEqual('DT');
711 expect(mel.children[0].children[0].attributes[0].name).toEqual('title');
712 expect(mel.children[0].children[1].tagName).toEqual('DD');
713
714 expect(mel.children[0].children[0].firstChild.nodeValue).toEqual('author');
715 expect(mel.children[0].children[1].firstChild.nodeValue).toEqual('Sprachpfleger, u.a.');
716 expect(mel.children[0].children[0].attributes[0].value).toEqual('author');
717 });
718
719
720 /* The keywords in the meta information list should be formatted to be able
721 to chose each keyword separately in the corpusByMatch assistant. */
722 it('keywords should be formatted', function(){
723
724 //type:string or type:keyword should b not relevant
725 expect(mel.children[1].children[1].classList.contains('metakeyvalues')).toBeTruthy;
726 expect(mel.children[1].children[1].children[0].tagName).toEqual('DIV');
727 expect(mel.children[1].children[1].children[0].firstChild.nodeValue).toEqual('corenlp');
728 expect(mel.children[1].children[1].children[1].tagName).toEqual('DIV');
729 expect(mel.children[1].children[1].children[1].firstChild.nodeValue).toEqual('corenlp\/constituency');
730
731 expect(mel.children[2].children[1].classList.contains('metakeyvalues')).toBeTruthy;
732 expect(mel.children[2].children[1].children[0].tagName).toEqual('DIV');
733 expect(mel.children[2].children[1].children[0].firstChild.nodeValue).toEqual('kultur');
734 expect(mel.children[2].children[1].children[1].tagName).toEqual('DIV');
735 expect(mel.children[2].children[1].children[1].firstChild.nodeValue).toEqual('film');
736 });
737
738
739 // Meta information should be sorted alphabetically
740 it('should be alphabetically sorted', function(){
741 var a = mel.children[0].children[0].firstChild.nodeValue;
742 var b = mel.children[1].children[0].firstChild.nodeValue;
743 var c = mel.children[2].children[0].firstChild.nodeValue;
744 expect(a.localeCompare(b)).toBe(-1);
745 expect(b.localeCompare(c)).toBe(-1);
746 });
747
748});
Nils Diewald7c8ced22015-04-15 19:21:00 +0000749 // table = view.toTable();
750 // table.sortBy('');
751 // table.element();
752 // tree = view.toTree();
753 // tree.element();
Nils Diewalda297f062015-04-02 00:23:46 +0000754});