blob: 2d1b49f1f4222604b54d4912d542f4219df0c8af [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
3
Nils Diewalda297f062015-04-02 00:23:46 +00004var available = [
5 'base/s=spans',
6 'corenlp/c=spans',
7 'corenlp/ne=tokens',
8 'corenlp/p=tokens',
9 'corenlp/s=spans',
10 'glemm/l=tokens',
11 'mate/l=tokens',
12 'mate/m=tokens',
13 'mate/p=tokens',
14 'opennlp/p=tokens',
15 'opennlp/s=spans',
16 'tt/l=tokens',
17 'tt/p=tokens',
18 'tt/s=spans'
19];
20
21var match = {
22 'corpusID' : 'WPD',
23 'docID' : 'UUU',
24 'textID' : '01912',
25 'matchID' : 'p121-122',
Akron0a6768f2016-07-13 18:00:43 +020026 'textSigle' : 'WPD/UUU/01912',
Nils Diewalda297f062015-04-02 00:23:46 +000027 'available' : available
28};
29
30var snippet = "<span title=\"cnx/l:meist\">" +
Akron4e47d0b2017-07-03 17:58:37 +020031 " <span title=\"cnx/p:ADV\">" +
32 " <span title=\"cnx/syn:@PREMOD\">" +
33 " <span title=\"mate/l:meist\">" +
34 " <span title=\"mate/l:meist\">" +
35 " <span title=\"mate/p:ADV\">" +
36 " <span title=\"opennlp/p:ADV\">meist</span>" +
37 " </span>" +
38 " </span>" +
39 " </span>" +
40 " </span>" +
41 " </span>" +
42 "</span>" +
43 "<span title=\"cnx/l:deutlich\">" +
44 " <span title=\"cnx/p:A\">" +
45 " <span title=\"cnx/syn:@PREMOD\">" +
46 " <span title=\"mate/l:deutlich\">" +
47 " <span title=\"mate/m:degree:pos\">" +
48 " <span title=\"mate/p:ADJD\">" +
49 " <span title=\"opennlp/p:ADJD\">deutlich</span>" +
50 " </span>" +
51 " </span>" +
52 " </span>" +
53 " </span>" +
54 " </span>" +
55 "</span>" +
56 "<span title=\"cnx/l:fähig\">" +
57 " <span title=\"cnx/l:leistung\">" +
58 " <span title=\"cnx/p:A\">" +
59 " <span title=\"cnx/p:ADJA\">" +
60 " <span title=\"cnx/syn:@NH\">" +
61 " <span title=\"mate/l:leistungsfähig\">" +
62 " <span title=\"mate/m:degree:comp\">" +
63 " <span title=\"mate/p:ADJD\">" +
64 " <span title=\"opennlp/p:ADJD\">leistungsfähiger</span>" +
65 " </span>" +
66 " </span>" +
67 " </span>" +
68 " </span>" +
69 " </span>" +
70 " </span>" +
71 " </span>" +
72 "</span>";
Nils Diewalda297f062015-04-02 00:23:46 +000073
74var treeSnippet =
75 "<span class=\"context-left\"></span>" +
76 "<span class=\"match\">" +
77 " <span title=\"xip/c:MC\">" +
78 " <span title=\"xip/c:TOP\">" +
79 " <span title=\"xip/c:PP\">" +
80 " <span title=\"xip/c:PREP\">Mit</span>" +
81 " <span title=\"xip/c:NP\">" +
82 " <span title=\"xip/c:DET\">dieser</span>" +
83 " <span title=\"xip/c:NPA\">" +
84 " <span title=\"xip/c:NOUN\">Methode</span>" +
85 " </span>" +
86 " </span>" +
87 " </span>" +
88 " <span title=\"xip/c:VERB\">ist</span>" +
Akron98a933f2016-08-11 00:19:17 +020089 " <mark>" +
90 " <span title=\"xip/c:NP\">" +
91 " <span title=\"xip/c:PRON\">es</span>" +
92 " </span>" +
93 " <span title=\"xip/c:AP\">" +
94 " <span title=\"xip/c:ADV\">nun</span>" +
95 " <span title=\"xip/c:ADJ\">möglich</span>" +
96 " </span>" +
97 " </mark>" +
Nils Diewalda297f062015-04-02 00:23:46 +000098 " <span title=\"xip/c:ADV\">z. B.</span>" +
99 " <span title=\"xip/c:NPA\">" +
100 " <span title=\"xip/c:NP\">" +
101 " <span title=\"xip/c:NOUN\">Voice</span>" +
102 " </span>" +
103 " </span>" + "(" +
104 " <span title=\"xip/c:INS\">" +
105 " <span title=\"xip/c:NPA\">" +
106 " <span title=\"xip/c:NP\">" +
107 " <span title=\"xip/c:NOUN\">Sprache</span>" +
108 " </span>" +
109 " </span>" +
110 " </span>" + ")" +
111 " <span title=\"xip/c:VERB\">bevorzugt</span>" +
112 " <span title=\"xip/c:PP\">" +
113 " <span title=\"xip/c:PREP\">in</span>" +
114 " <span title=\"xip/c:NP\">" +
115 " <span title=\"xip/c:PRON\">der</span>" +
116 " </span>" +
117 " <span title=\"xip/c:NPA\">" +
118 " <span title=\"xip/c:NP\">" +
119 " <span title=\"xip/c:NOUN\">Bridge</span>" +
120 " </span>" +
121 " </span>" +
122 " </span>" +
123 " <span title=\"xip/c:INFC\">" +
124 " <span title=\"xip/c:INS\">" +
125 " <span title=\"xip/c:VERB\">weiterzugeben</span>" +
126 " </span>" +
127 " </span>" +
128 " </span>" +
129 " </span>" +
130 "</span>" +
131 "<span class=\"context-right\"></span>";
132
133
134function matchElementFactory () {
135 var me = document.createElement('li');
136
137 me.setAttribute(
138 'data-available-info',
139 'base/s=spans corenlp/c=spans corenlp/ne=tokens corenlp/p=tokens' +
140 ' corenlp/s=spans glemm/l=tokens mate/l=tokens mate/m=tokens' +
141 ' mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens' +
142 ' tt/p=tokens tt/s=spans');
143
144 me.setAttribute('data-corpus-id', 'WPD');
145 me.setAttribute('data-doc-id', 'FFF');
146 me.setAttribute('data-text-id', '01460');
Akron0a6768f2016-07-13 18:00:43 +0200147 me.setAttribute('data-text-sigle', 'WPD/FFF/01460');
Nils Diewalda297f062015-04-02 00:23:46 +0000148 me.setAttribute('data-match-id', 'p119-120');
149 me.innerHTML = '<div><div class="snippet">check</div></div><p class="ref">me</p>';
150 return me;
151};
152
Akroncdb0baa2016-11-07 01:52:11 +0100153function matchElementReal () {
154 var me = document.createElement('em');
155 me.innerHTML =
156 '<li data-match-id="p85183-85184"' +
157 ' data-text-sigle="GOE/AGI/00000"' +
158 ' 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"' +
159 ' 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;}"' +
160 ' id="GOE/AGI/00000#p85183-85184">' +
161 '<div>' +
162 '<div class="flag"></div>' +
163 '<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>' +
164 '</div>' +
165 '<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>' +
166 '</li>';
167 return me.firstChild;
168};
Nils Diewalda297f062015-04-02 00:23:46 +0000169
Akronf2279c42017-12-21 13:48:46 +0100170define(['match', 'hint/foundries/cnx', 'hint/foundries/mate'], function () {
Nils Diewald58141332015-04-07 16:18:45 +0000171
Nils Diewald7c8ced22015-04-15 19:21:00 +0000172 // Override getMatchInfo API call
173 KorAP.API.getMatchInfo = function (x, param, cb) {
174 if (param['spans'] === undefined || param['spans'] === false)
175 cb({ "snippet": snippet });
176 else
177 cb({ "snippet": treeSnippet });
Nils Diewalda297f062015-04-02 00:23:46 +0000178 };
Akron671fdb92017-09-12 18:09:46 +0200179
Nils Diewald7c8ced22015-04-15 19:21:00 +0000180 describe('KorAP.InfoLayer', function () {
181
182 var infoClass = require('match/infolayer');
Nils Diewalda297f062015-04-02 00:23:46 +0000183
Nils Diewald7c8ced22015-04-15 19:21:00 +0000184 it('should be initializable', function () {
185 expect(
Akron671fdb92017-09-12 18:09:46 +0200186 function() { infoClass.create() }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000187 ).toThrow(new Error("Missing parameters"));
Nils Diewalda297f062015-04-02 00:23:46 +0000188
Nils Diewald7c8ced22015-04-15 19:21:00 +0000189 expect(
Akron671fdb92017-09-12 18:09:46 +0200190 function() { infoClass.create("base") }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000191 ).toThrow(new Error("Missing parameters"));
Nils Diewalda297f062015-04-02 00:23:46 +0000192
Nils Diewald7c8ced22015-04-15 19:21:00 +0000193 var layer = infoClass.create("base", "s");
194 expect(layer).toBeTruthy();
195 expect(layer.foundry).toEqual("base");
196 expect(layer.layer).toEqual("s");
197 expect(layer.type).toEqual("tokens");
Nils Diewalda297f062015-04-02 00:23:46 +0000198
Nils Diewald7c8ced22015-04-15 19:21:00 +0000199 layer = infoClass.create("cnx", "syn", "spans");
200 expect(layer).toBeTruthy();
201 expect(layer.foundry).toEqual("cnx");
202 expect(layer.layer).toEqual("syn");
203 expect(layer.type).toEqual("spans");
Nils Diewald58141332015-04-07 16:18:45 +0000204 });
205 });
Nils Diewalda297f062015-04-02 00:23:46 +0000206
Nils Diewalda297f062015-04-02 00:23:46 +0000207
Nils Diewald7c8ced22015-04-15 19:21:00 +0000208 describe('KorAP.Match', function () {
209 var match = {
210 'corpusID' : 'WPD',
211 'docID' : 'UUU',
212 'textID' : '01912',
213 'matchID' : 'p121-122',
Akron0a6768f2016-07-13 18:00:43 +0200214 'textSigle' : 'WPD/UUU/01912',
Nils Diewald7c8ced22015-04-15 19:21:00 +0000215 'available' : available
216 };
217
218 var matchClass = require('match');
219
220 it('should be initializable by Object', function () {
221 expect(function() {
Akron671fdb92017-09-12 18:09:46 +0200222 matchClass.create()
Nils Diewald7c8ced22015-04-15 19:21:00 +0000223 }).toThrow(new Error('Missing parameters'));
224
225 expect(matchClass.create(match)).toBeTruthy();
226
227 var m = matchClass.create(match);
Akron0a6768f2016-07-13 18:00:43 +0200228 expect(m.textSigle).toEqual("WPD/UUU/01912");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000229 expect(m.matchID).toEqual("p121-122");
230
231 // /corpus/WPD/UUU.01912/p121-122/matchInfo?spans=false&foundry=*
232 var m = matchClass.create(match);
233
234 // Spans:
235 var spans = m.getSpans();
236 expect(spans[0].foundry).toEqual("base");
237 expect(spans[0].layer).toEqual("s");
238
239 expect(spans[1].foundry).toEqual("corenlp");
240 expect(spans[1].layer).toEqual("c");
241
242 expect(spans[2].foundry).toEqual("corenlp");
243 expect(spans[2].layer).toEqual("s");
244
245 expect(spans[spans.length-1].foundry).toEqual("tt");
246 expect(spans[spans.length-1].layer).toEqual("s");
247
248 // Tokens:
249 var tokens = m.getTokens();
250 expect(tokens[0].foundry).toEqual("corenlp");
251 expect(tokens[0].layer).toEqual("ne");
252
253 expect(tokens[1].foundry).toEqual("corenlp");
254 expect(tokens[1].layer).toEqual("p");
255
256 expect(tokens[tokens.length-1].foundry).toEqual("tt");
257 expect(tokens[tokens.length-1].layer).toEqual("p");
Nils Diewald58141332015-04-07 16:18:45 +0000258 });
Nils Diewalda297f062015-04-02 00:23:46 +0000259
260
Akroncdb0baa2016-11-07 01:52:11 +0100261 it('should be initializable by Node 1', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000262 var m = matchClass.create(matchElementFactory());
Akron0a6768f2016-07-13 18:00:43 +0200263 expect(m.textSigle).toEqual("WPD/FFF/01460");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000264 expect(m.matchID).toEqual("p119-120");
Nils Diewalda297f062015-04-02 00:23:46 +0000265
Nils Diewald7c8ced22015-04-15 19:21:00 +0000266 // Spans:
267 var spans = m.getSpans();
268 expect(spans[0].foundry).toEqual("base");
269 expect(spans[0].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000270
Nils Diewald7c8ced22015-04-15 19:21:00 +0000271 expect(spans[1].foundry).toEqual("corenlp");
272 expect(spans[1].layer).toEqual("c");
Nils Diewalda297f062015-04-02 00:23:46 +0000273
Nils Diewald7c8ced22015-04-15 19:21:00 +0000274 expect(spans[2].foundry).toEqual("corenlp");
275 expect(spans[2].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000276
Nils Diewald7c8ced22015-04-15 19:21:00 +0000277 expect(spans[spans.length-1].foundry).toEqual("tt");
278 expect(spans[spans.length-1].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000279
Nils Diewald7c8ced22015-04-15 19:21:00 +0000280 // Tokens:
281 var tokens = m.getTokens();
282 expect(tokens[0].foundry).toEqual("corenlp");
283 expect(tokens[0].layer).toEqual("ne");
Nils Diewalda297f062015-04-02 00:23:46 +0000284
Nils Diewald7c8ced22015-04-15 19:21:00 +0000285 expect(tokens[1].foundry).toEqual("corenlp");
286 expect(tokens[1].layer).toEqual("p");
Nils Diewalda297f062015-04-02 00:23:46 +0000287
Nils Diewald7c8ced22015-04-15 19:21:00 +0000288 expect(tokens[tokens.length-1].foundry).toEqual("tt");
289 expect(tokens[tokens.length-1].layer).toEqual("p");
Nils Diewalda297f062015-04-02 00:23:46 +0000290
Nils Diewald7c8ced22015-04-15 19:21:00 +0000291 });
Nils Diewalda297f062015-04-02 00:23:46 +0000292
Akroncdb0baa2016-11-07 01:52:11 +0100293 it('should be initializable by Node 2', function () {
294 var ele = matchElementReal();
295 var m = matchClass.create(ele);
296 expect(m.textSigle).toEqual("GOE/AGI/00000");
297 expect(m.matchID).toEqual("p85183-85184");
298 });
299
300
Nils Diewald7c8ced22015-04-15 19:21:00 +0000301 it('should react to gui actions', function () {
302 var e = matchElementFactory();
Nils Diewalda297f062015-04-02 00:23:46 +0000303
Nils Diewald7c8ced22015-04-15 19:21:00 +0000304 expect(e.classList.contains('active')).toBe(false);
305 expect(e["_match"]).toBe(undefined);
Nils Diewalda297f062015-04-02 00:23:46 +0000306
Nils Diewald7c8ced22015-04-15 19:21:00 +0000307 var m = matchClass.create(e);
308
309 expect(e.classList.contains('active')).toBe(false);
310 expect(e["_match"]).not.toBe(undefined);
311
312 // Open the match
313 m.open();
314
315 expect(e.classList.contains('active')).toBe(true);
316 expect(e["_match"]).not.toBe(undefined);
317
318 // Close the match
319 m.close();
320 expect(e.classList.contains('active')).toBe(false);
321 expect(e["_match"]).not.toBe(undefined);
322
Nils Diewald58141332015-04-07 16:18:45 +0000323 });
324 });
Nils Diewalda297f062015-04-02 00:23:46 +0000325
Nils Diewald7c8ced22015-04-15 19:21:00 +0000326
327 describe('KorAP.MatchInfo', function () {
328
329 var matchClass = require('match');
330
331 var m = matchClass.create(match);
332 var info = m.info();
333
334 it('should contain a valid info', function () {
335 expect(m._info).toEqual(info);
336 });
337
338 var table1, table2;
339
340 // Async preparation
341 it('should fail to load a table async', function (done) {
342 expect(info).toBeTruthy();
343
Akron5b1a6af2018-02-05 15:41:16 +0100344 info.getTableData([], function (tablen) {
Akron671fdb92017-09-12 18:09:46 +0200345 table1 = tablen;
346 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000347 });
348 });
349
Akron671fdb92017-09-12 18:09:46 +0200350
Nils Diewald7c8ced22015-04-15 19:21:00 +0000351 it('should\'nt be parsable (async)', function () {
352 expect(table1).not.toBeTruthy();
353 });
354
Akron671fdb92017-09-12 18:09:46 +0200355
Nils Diewald7c8ced22015-04-15 19:21:00 +0000356 it('should load a working table async', function(done) {
357 expect(info).toBeTruthy();
Akron5b1a6af2018-02-05 15:41:16 +0100358 info.getTableData(undefined, function (tablem) {
Akron671fdb92017-09-12 18:09:46 +0200359 table2 = tablem;
360 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000361 });
362 });
363
Akron671fdb92017-09-12 18:09:46 +0200364
Nils Diewald7c8ced22015-04-15 19:21:00 +0000365 it('should parse into a table (async)', function () {
366 expect(table2).toBeTruthy();
367
368 expect(table2.length()).toBe(3);
369
370 expect(table2.getToken(0)).toBe("meist");
371 expect(table2.getToken(1)).toBe("deutlich");
372 expect(table2.getToken(2)).toBe("leistungsfähiger");
373
374 expect(table2.getValue(0, "cnx", "p")[0]).toBe("ADV");
375 expect(table2.getValue(0, "cnx", "syn")[0]).toBe("@PREMOD");
Akron916ec252016-11-10 17:06:32 +0100376 expect(table2.getValue(0, "mate", "l")[0]).toBe("meist");
377 expect(table2.getValue(0, "mate", "l")[1]).toBeUndefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000378
379 expect(table2.getValue(2, "cnx", "l")[0]).toBe("fähig");
380 expect(table2.getValue(2, "cnx", "l")[1]).toBe("leistung");
381 });
382
Akron671fdb92017-09-12 18:09:46 +0200383
Nils Diewald7c8ced22015-04-15 19:21:00 +0000384 it('should parse into a table view', function () {
385 var matchElement = matchElementFactory();
386 expect(matchElement.tagName).toEqual('LI');
387
388 // Match
389 expect(matchElement.children[0].tagName).toEqual('DIV');
390
391 // snippet
392 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
393 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
394 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
395
396 // reference
397 expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
398 expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
399
400 // not yet
401 expect(matchElement.children[0].children[1]).toBe(undefined);
402
403 var info = matchClass.create(matchElement).info();
Akron5b1a6af2018-02-05 15:41:16 +0100404 info.showTable();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000405
406 // Match
407 expect(matchElement.children[0].tagName).toEqual('DIV');
408
409 // snippet
410 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
Akron5b1a6af2018-02-05 15:41:16 +0100411
Nils Diewald7c8ced22015-04-15 19:21:00 +0000412 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
Akron5b1a6af2018-02-05 15:41:16 +0100413
Nils Diewald7c8ced22015-04-15 19:21:00 +0000414 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
415
416 // reference
Akron5b1a6af2018-02-05 15:41:16 +0100417 expect(matchElement.lastChild.classList.contains('ref')).toBeTruthy();
418 expect(matchElement.lastChild.firstChild.nodeValue).toEqual('me');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000419
420 // now
Akron5b1a6af2018-02-05 15:41:16 +0100421 var infotable = matchElement.children[1];
Nils Diewald7c8ced22015-04-15 19:21:00 +0000422 expect(infotable.tagName).toEqual('DIV');
Akronaa7fce52017-06-30 21:15:18 +0200423
Nils Diewald7c8ced22015-04-15 19:21:00 +0000424 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
425
426 expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
Akron5b1a6af2018-02-05 15:41:16 +0100427 // expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000428 });
429
Akron671fdb92017-09-12 18:09:46 +0200430
Nils Diewald7c8ced22015-04-15 19:21:00 +0000431 var tree;
432 it('should parse into a tree (async) 1', function (done) {
433 var info = matchClass.create(match).info();
434 expect(info).toBeTruthy();
Akron5b1a6af2018-02-05 15:41:16 +0100435 info.getTreeData(undefined, undefined, "spans", function (treem) {
Akron671fdb92017-09-12 18:09:46 +0200436 tree = treem;
437 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000438 });
439 });
440
Akron671fdb92017-09-12 18:09:46 +0200441
Nils Diewald7c8ced22015-04-15 19:21:00 +0000442 it('should parse into a tree (async) 2', function () {
443 expect(tree).toBeTruthy();
444 expect(tree.nodes()).toEqual(49);
445 });
Nils Diewalda297f062015-04-02 00:23:46 +0000446
Akron671fdb92017-09-12 18:09:46 +0200447
Akron98a933f2016-08-11 00:19:17 +0200448 var matchElement, info;
Akron5b1a6af2018-02-05 15:41:16 +0100449
Akron98a933f2016-08-11 00:19:17 +0200450 // var info, matchElement;
451 it('should parse into a tree view', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000452 matchElement = matchElementFactory();
453 expect(matchElement.tagName).toEqual('LI');
Nils Diewalda297f062015-04-02 00:23:46 +0000454
Nils Diewald7c8ced22015-04-15 19:21:00 +0000455 info = matchClass.create(matchElement).info();
Akron5b1a6af2018-02-05 15:41:16 +0100456 info.showTable();
Nils Diewalda297f062015-04-02 00:23:46 +0000457
Nils Diewald7c8ced22015-04-15 19:21:00 +0000458 // Match
459 expect(matchElement.children[0].tagName).toEqual('DIV');
Nils Diewalda297f062015-04-02 00:23:46 +0000460
Nils Diewald7c8ced22015-04-15 19:21:00 +0000461 // snippet
462 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
463 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
464 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
Nils Diewalda297f062015-04-02 00:23:46 +0000465
Nils Diewald7c8ced22015-04-15 19:21:00 +0000466 // reference
Akron5b1a6af2018-02-05 15:41:16 +0100467 expect(matchElement.lastChild.classList.contains('ref')).toBeTruthy();
468 expect(matchElement.lastChild.firstChild.nodeValue).toEqual('me');
Nils Diewalda297f062015-04-02 00:23:46 +0000469
Nils Diewald7c8ced22015-04-15 19:21:00 +0000470 // now
Akron5b1a6af2018-02-05 15:41:16 +0100471 var infotable = matchElement.children[1];
Nils Diewald7c8ced22015-04-15 19:21:00 +0000472 expect(infotable.tagName).toEqual('DIV');
473 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
474 expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
Akron5b1a6af2018-02-05 15:41:16 +0100475 // expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000476 });
Nils Diewalda297f062015-04-02 00:23:46 +0000477
Akron671fdb92017-09-12 18:09:46 +0200478
Nils Diewald7c8ced22015-04-15 19:21:00 +0000479 it('should add a tree view async 1', function (done) {
480 expect(info).toBeTruthy();
Akron5b1a6af2018-02-05 15:41:16 +0100481 info.showTree('mate', 'beebop', "spans", function () {
Akron671fdb92017-09-12 18:09:46 +0200482 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000483 });
484 });
485
Akron671fdb92017-09-12 18:09:46 +0200486
Nils Diewald7c8ced22015-04-15 19:21:00 +0000487 it('should add a tree view async 2', function () {
488 // With added tree
Akron5b1a6af2018-02-05 15:41:16 +0100489 var infotable = matchElement.children[1];
490
Nils Diewald7c8ced22015-04-15 19:21:00 +0000491 expect(infotable.tagName).toEqual('DIV');
492 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
493 expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
494 expect(infotable.children[1].classList.contains('addtree')).toBe(false);
495
496 var tree = infotable.children[1];
497 expect(tree.tagName).toEqual('DIV');
498 expect(tree.classList.contains('matchtree')).toBeTruthy();
499 expect(tree.children[0].tagName).toEqual('H6');
500 expect(tree.children[0].children[0].tagName).toEqual('SPAN');
501 expect(tree.children[0].children[0].firstChild.nodeValue).toEqual('mate');
502 expect(tree.children[0].children[1].tagName).toEqual('SPAN');
503 expect(tree.children[0].children[1].firstChild.nodeValue).toEqual('beebop');
504
505 expect(tree.children[1].tagName).toEqual('DIV');
Nils Diewald58141332015-04-07 16:18:45 +0000506 });
507 });
Nils Diewalda297f062015-04-02 00:23:46 +0000508
Nils Diewalda297f062015-04-02 00:23:46 +0000509
Nils Diewald7c8ced22015-04-15 19:21:00 +0000510 describe('KorAP.MatchTable', function () {
Nils Diewalda297f062015-04-02 00:23:46 +0000511
Nils Diewald7c8ced22015-04-15 19:21:00 +0000512 var matchClass = require('match');
Nils Diewalda297f062015-04-02 00:23:46 +0000513
Nils Diewald7c8ced22015-04-15 19:21:00 +0000514 var table;
515 it('should be retrieved async', function (done) {
516 var info = matchClass.create(match).info();
517 expect(info).toBeTruthy();
Akron5b1a6af2018-02-05 15:41:16 +0100518 info.getTableData(undefined, function (x) {
Akron671fdb92017-09-12 18:09:46 +0200519 table = x;
520 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000521 });
522 });
Nils Diewalda297f062015-04-02 00:23:46 +0000523
Nils Diewald7c8ced22015-04-15 19:21:00 +0000524 it('should be rendered async', function () {
Akron5b1a6af2018-02-05 15:41:16 +0100525
526 var e = table.element().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000527 expect(e.nodeName).toBe('TABLE');
528 expect(e.children[0].nodeName).toBe('THEAD');
529 var tr = e.children[0].children[0];
530 expect(tr.nodeName).toBe('TR');
531 expect(tr.children[0].nodeName).toBe('TH');
Nils Diewald58141332015-04-07 16:18:45 +0000532
Nils Diewald7c8ced22015-04-15 19:21:00 +0000533 expect(tr.children[0].firstChild.nodeValue).toBe('Foundry');
534 expect(tr.children[1].firstChild.nodeValue).toBe('Layer');
535 expect(tr.children[2].firstChild.nodeValue).toBe('meist');
536 expect(tr.children[3].firstChild.nodeValue).toBe('deutlich');
537 expect(tr.children[4].firstChild.nodeValue).toBe('leistungsfähiger');
538
539 // first row
540 tr = e.children[1].children[0];
541 expect(tr.nodeName).toBe('TR');
542 expect(tr.getAttribute('tabindex')).toEqual('0');
543 expect(tr.children[0].nodeName).toBe('TH');
544 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
545 expect(tr.children[1].firstChild.nodeValue).toEqual('l');
546 expect(tr.children[2].firstChild.nodeValue).toEqual('meist');
547 expect(tr.children[3].firstChild.nodeValue).toEqual('deutlich');
Akron47774c42017-07-03 20:14:55 +0200548 expect(tr.children[4].firstChild.firstChild.nodeValue).toEqual('fähig');
549 expect(tr.children[4].lastChild.firstChild.nodeValue).toEqual('leistung');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000550
551 // second row
552 tr = e.children[1].children[1];
553 expect(tr.nodeName).toBe('TR');
554 expect(tr.getAttribute('tabindex')).toEqual('0');
555 expect(tr.children[0].nodeName).toBe('TH');
556 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
557 expect(tr.children[1].firstChild.nodeValue).toEqual('p');
558 expect(tr.children[2].firstChild.nodeValue).toEqual('ADV');
559 expect(tr.children[3].firstChild.nodeValue).toEqual('A');
Akron47774c42017-07-03 20:14:55 +0200560 expect(tr.children[4].firstChild.firstChild.nodeValue).toEqual('A');
561 expect(tr.children[4].lastChild.firstChild.nodeValue).toEqual('ADJA');
Akronf2279c42017-12-21 13:48:46 +0100562
563 expect(tr.children[4].firstChild.getAttribute("title")).toEqual('Adjective');
564 expect(tr.children[2].getAttribute("title")).toEqual('Adverb');
565
Nils Diewald58141332015-04-07 16:18:45 +0000566 });
567 });
Nils Diewalda297f062015-04-02 00:23:46 +0000568
Nils Diewald7c8ced22015-04-15 19:21:00 +0000569 describe('KorAP.MatchTree', function () {
570 var tree;
571 var matchClass = require('match');
Nils Diewalda297f062015-04-02 00:23:46 +0000572
Nils Diewald7c8ced22015-04-15 19:21:00 +0000573 it('should be rendered async 1', function (done) {
574 var info = matchClass.create(match).info();
575 expect(info).toBeTruthy();
Akron5b1a6af2018-02-05 15:41:16 +0100576 info.getTreeData(undefined, undefined, "spans", function (y) {
Akron671fdb92017-09-12 18:09:46 +0200577 tree = y;
578 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000579 });
580 });
Nils Diewalda297f062015-04-02 00:23:46 +0000581
Nils Diewald7c8ced22015-04-15 19:21:00 +0000582 it('should be rendered async 2', function () {
583 var e = tree.element();
584 expect(e.nodeName).toEqual('svg');
585 expect(e.getElementsByTagName('g').length).toEqual(48);
Nils Diewald58141332015-04-07 16:18:45 +0000586 });
587 });
Nils Diewalda297f062015-04-02 00:23:46 +0000588
Nils Diewald7c8ced22015-04-15 19:21:00 +0000589
590 describe('KorAP.MatchTreeItem', function () {
591 var matchTreeItemClass = require('match/treeitem');
592 it('should be initializable', function () {
593 var mi = matchTreeItemClass.create(['cnx/c', 'cnx', 'c'])
594 expect(mi.element().firstChild.nodeValue).toEqual('cnx/c');
595 expect(mi.lcField()).toEqual(' cnx/c');
596 expect(mi.foundry()).toEqual('cnx');
597 expect(mi.layer()).toEqual('c');
598 });
Nils Diewalda297f062015-04-02 00:23:46 +0000599 });
Nils Diewalda297f062015-04-02 00:23:46 +0000600
601
Akron671fdb92017-09-12 18:09:46 +0200602 describe('KorAP.MatchRelation', function () {
Akron41387d22018-02-02 18:10:06 +0100603 var relClass = require('match/treearc')
Akron671fdb92017-09-12 18:09:46 +0200604
605 var relExample = "<span class=\"context-left\"></span>" +
606 "<span class=\"match\">" +
607 " <span xml:id=\"token-GOE/AGA/01784-p199\">" +
608 " <span xlink:title=\"malt/d:ADV\" " +
609 " xlink:type=\"simple\" " +
610 " xlink:href=\"#token-GOE/AGA/01784-p199\">dann</span>" +
611 " </span>" +
612 " zog " +
613 " <span xlink:title=\"malt/d:SUBJ\" " +
614 " xlink:type=\"simple\" " +
615 " xlink:href=\"#token-GOE/AGA/01784-p199\">ich</span>" +
616 " <span xml:id=\"token-GOE/AGA/01784-p202\">" +
617 " <span xlink:title=\"malt/d:OBJA\" " +
618 " xlink:type=\"simple\" " +
619 " xlink:href=\"#token-GOE/AGA/01784-p199\">mich</span>" +
620 " </span>" +
621 "</span>" +
622 "<span class=\"context-right\"></span>";
623
624
625 it('should be initializable', function () {
626 var tree = relClass.create();
627 expect(tree.size()).toBe(0);
628 });
629
630 it('should be parse string data', function () {
631 var tree = relClass.create(relExample);
632 expect(tree.size()).toBe(4);
633 });
634
635
636 });
637
638
Nils Diewald7c8ced22015-04-15 19:21:00 +0000639 describe('KorAP.MatchTreeMenu', function () {
640 var matchTreeMenu = require('match/treemenu');
641 var matchTreeItem = require('match/treeitem');
642
643 it('should be initializable', function () {
Akron5b1a6af2018-02-05 15:41:16 +0100644 var menu = matchTreeMenu.create([
Akron671fdb92017-09-12 18:09:46 +0200645 ['cnx/c', 'cnx', 'c'],
646 ['xip/c', 'xip', 'c']
Nils Diewald7c8ced22015-04-15 19:21:00 +0000647 ]);
648
649 expect(menu.itemClass()).toEqual(matchTreeItem);
650 expect(menu.element().nodeName).toEqual('UL');
Akronaba7a5a2016-08-15 21:58:33 +0200651 expect(menu.element().classList.contains('visible')).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000652 expect(menu.limit()).toEqual(6);
653 menu.show();
Akronaba7a5a2016-08-15 21:58:33 +0200654 expect(menu.element().classList.contains('visible')).toBeTruthy();
Akronc1457bf2015-06-11 19:24:00 +0200655 expect(menu.item(0).active()).toBe(false);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000656 });
Nils Diewalda297f062015-04-02 00:23:46 +0000657 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000658
659 // table = view.toTable();
660 // table.sortBy('');
661 // table.element();
662 // tree = view.toTree();
663 // tree.element();
Nils Diewalda297f062015-04-02 00:23:46 +0000664});