blob: 68bd98187e843472200cbfb3849adc60860d496a [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
Nils Diewald7c8ced22015-04-15 19:21:00 +0000170define(['match'], 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
344 info.getTable([], 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();
358 info.getTable(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();
404 info.toggle();
405
406 // Match
407 expect(matchElement.children[0].tagName).toEqual('DIV');
408
409 // snippet
410 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
411 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
412 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
413
414 // reference
415 expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
416 expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
417
418 // now
Akronaa7fce52017-06-30 21:15:18 +0200419 var infotable = matchElement.children[2];
Nils Diewald7c8ced22015-04-15 19:21:00 +0000420 expect(infotable.tagName).toEqual('DIV');
Akronaa7fce52017-06-30 21:15:18 +0200421
Nils Diewald7c8ced22015-04-15 19:21:00 +0000422 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
423
424 expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
425 expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
426 });
427
Akron671fdb92017-09-12 18:09:46 +0200428
Nils Diewald7c8ced22015-04-15 19:21:00 +0000429 var tree;
430 it('should parse into a tree (async) 1', function (done) {
431 var info = matchClass.create(match).info();
432 expect(info).toBeTruthy();
433 info.getTree(undefined, undefined, function (treem) {
Akron671fdb92017-09-12 18:09:46 +0200434 tree = treem;
435 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000436 });
437 });
438
Akron671fdb92017-09-12 18:09:46 +0200439
Nils Diewald7c8ced22015-04-15 19:21:00 +0000440 it('should parse into a tree (async) 2', function () {
441 expect(tree).toBeTruthy();
442 expect(tree.nodes()).toEqual(49);
443 });
Nils Diewalda297f062015-04-02 00:23:46 +0000444
Akron671fdb92017-09-12 18:09:46 +0200445
Akron98a933f2016-08-11 00:19:17 +0200446 var matchElement, info;
447 // var info, matchElement;
448 it('should parse into a tree view', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000449 matchElement = matchElementFactory();
450 expect(matchElement.tagName).toEqual('LI');
Nils Diewalda297f062015-04-02 00:23:46 +0000451
Nils Diewald7c8ced22015-04-15 19:21:00 +0000452 info = matchClass.create(matchElement).info();
453 info.toggle();
Nils Diewalda297f062015-04-02 00:23:46 +0000454
Nils Diewald7c8ced22015-04-15 19:21:00 +0000455 // Match
456 expect(matchElement.children[0].tagName).toEqual('DIV');
Nils Diewalda297f062015-04-02 00:23:46 +0000457
Nils Diewald7c8ced22015-04-15 19:21:00 +0000458 // snippet
459 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
460 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
461 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
Nils Diewalda297f062015-04-02 00:23:46 +0000462
Nils Diewald7c8ced22015-04-15 19:21:00 +0000463 // reference
464 expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
465 expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
Nils Diewalda297f062015-04-02 00:23:46 +0000466
Nils Diewald7c8ced22015-04-15 19:21:00 +0000467 // now
Akronaa7fce52017-06-30 21:15:18 +0200468 var infotable = matchElement.children[2];
Nils Diewald7c8ced22015-04-15 19:21:00 +0000469 expect(infotable.tagName).toEqual('DIV');
470 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
471 expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
472 expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
473 });
Nils Diewalda297f062015-04-02 00:23:46 +0000474
Akron671fdb92017-09-12 18:09:46 +0200475
Nils Diewald7c8ced22015-04-15 19:21:00 +0000476 it('should add a tree view async 1', function (done) {
477 expect(info).toBeTruthy();
478 info.addTree('mate', 'beebop', function () {
Akron671fdb92017-09-12 18:09:46 +0200479 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000480 });
481 });
482
Akron671fdb92017-09-12 18:09:46 +0200483
Nils Diewald7c8ced22015-04-15 19:21:00 +0000484 it('should add a tree view async 2', function () {
485 // With added tree
Akronaa7fce52017-06-30 21:15:18 +0200486 var infotable = matchElement.children[2];
Nils Diewald7c8ced22015-04-15 19:21:00 +0000487 expect(infotable.tagName).toEqual('DIV');
488 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
489 expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
490 expect(infotable.children[1].classList.contains('addtree')).toBe(false);
491
492 var tree = infotable.children[1];
493 expect(tree.tagName).toEqual('DIV');
494 expect(tree.classList.contains('matchtree')).toBeTruthy();
495 expect(tree.children[0].tagName).toEqual('H6');
496 expect(tree.children[0].children[0].tagName).toEqual('SPAN');
497 expect(tree.children[0].children[0].firstChild.nodeValue).toEqual('mate');
498 expect(tree.children[0].children[1].tagName).toEqual('SPAN');
499 expect(tree.children[0].children[1].firstChild.nodeValue).toEqual('beebop');
500
501 expect(tree.children[1].tagName).toEqual('DIV');
Nils Diewald58141332015-04-07 16:18:45 +0000502 });
503 });
Nils Diewalda297f062015-04-02 00:23:46 +0000504
Nils Diewalda297f062015-04-02 00:23:46 +0000505
Nils Diewald7c8ced22015-04-15 19:21:00 +0000506 describe('KorAP.MatchTable', function () {
Nils Diewalda297f062015-04-02 00:23:46 +0000507
Nils Diewald7c8ced22015-04-15 19:21:00 +0000508 var matchClass = require('match');
Nils Diewalda297f062015-04-02 00:23:46 +0000509
Nils Diewald7c8ced22015-04-15 19:21:00 +0000510 var table;
511 it('should be retrieved async', function (done) {
512 var info = matchClass.create(match).info();
513 expect(info).toBeTruthy();
514 info.getTable(undefined, function (x) {
Akron671fdb92017-09-12 18:09:46 +0200515 table = x;
516 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000517 });
518 });
Nils Diewalda297f062015-04-02 00:23:46 +0000519
Nils Diewald7c8ced22015-04-15 19:21:00 +0000520 it('should be rendered async', function () {
521 var e = table.element();
522
523 expect(e.nodeName).toBe('TABLE');
524 expect(e.children[0].nodeName).toBe('THEAD');
525 var tr = e.children[0].children[0];
526 expect(tr.nodeName).toBe('TR');
527 expect(tr.children[0].nodeName).toBe('TH');
Nils Diewald58141332015-04-07 16:18:45 +0000528
Nils Diewald7c8ced22015-04-15 19:21:00 +0000529 expect(tr.children[0].firstChild.nodeValue).toBe('Foundry');
530 expect(tr.children[1].firstChild.nodeValue).toBe('Layer');
531 expect(tr.children[2].firstChild.nodeValue).toBe('meist');
532 expect(tr.children[3].firstChild.nodeValue).toBe('deutlich');
533 expect(tr.children[4].firstChild.nodeValue).toBe('leistungsfähiger');
534
535 // first row
536 tr = e.children[1].children[0];
537 expect(tr.nodeName).toBe('TR');
538 expect(tr.getAttribute('tabindex')).toEqual('0');
539 expect(tr.children[0].nodeName).toBe('TH');
540 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
541 expect(tr.children[1].firstChild.nodeValue).toEqual('l');
542 expect(tr.children[2].firstChild.nodeValue).toEqual('meist');
543 expect(tr.children[3].firstChild.nodeValue).toEqual('deutlich');
Akron47774c42017-07-03 20:14:55 +0200544 expect(tr.children[4].firstChild.firstChild.nodeValue).toEqual('fähig');
545 expect(tr.children[4].lastChild.firstChild.nodeValue).toEqual('leistung');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000546
547 // second row
548 tr = e.children[1].children[1];
549 expect(tr.nodeName).toBe('TR');
550 expect(tr.getAttribute('tabindex')).toEqual('0');
551 expect(tr.children[0].nodeName).toBe('TH');
552 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
553 expect(tr.children[1].firstChild.nodeValue).toEqual('p');
554 expect(tr.children[2].firstChild.nodeValue).toEqual('ADV');
555 expect(tr.children[3].firstChild.nodeValue).toEqual('A');
Akron47774c42017-07-03 20:14:55 +0200556 expect(tr.children[4].firstChild.firstChild.nodeValue).toEqual('A');
557 expect(tr.children[4].lastChild.firstChild.nodeValue).toEqual('ADJA');
Nils Diewald58141332015-04-07 16:18:45 +0000558 });
559 });
Nils Diewalda297f062015-04-02 00:23:46 +0000560
Nils Diewald7c8ced22015-04-15 19:21:00 +0000561 describe('KorAP.MatchTree', function () {
562 var tree;
563 var matchClass = require('match');
Nils Diewalda297f062015-04-02 00:23:46 +0000564
Nils Diewald7c8ced22015-04-15 19:21:00 +0000565 it('should be rendered async 1', function (done) {
566 var info = matchClass.create(match).info();
567 expect(info).toBeTruthy();
568 info.getTree(undefined, undefined, function (y) {
Akron671fdb92017-09-12 18:09:46 +0200569 tree = y;
570 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000571 });
572 });
Nils Diewalda297f062015-04-02 00:23:46 +0000573
Nils Diewald7c8ced22015-04-15 19:21:00 +0000574 it('should be rendered async 2', function () {
575 var e = tree.element();
576 expect(e.nodeName).toEqual('svg');
577 expect(e.getElementsByTagName('g').length).toEqual(48);
Nils Diewald58141332015-04-07 16:18:45 +0000578 });
579 });
Nils Diewalda297f062015-04-02 00:23:46 +0000580
Nils Diewald7c8ced22015-04-15 19:21:00 +0000581
582 describe('KorAP.MatchTreeItem', function () {
583 var matchTreeItemClass = require('match/treeitem');
584 it('should be initializable', function () {
585 var mi = matchTreeItemClass.create(['cnx/c', 'cnx', 'c'])
586 expect(mi.element().firstChild.nodeValue).toEqual('cnx/c');
587 expect(mi.lcField()).toEqual(' cnx/c');
588 expect(mi.foundry()).toEqual('cnx');
589 expect(mi.layer()).toEqual('c');
590 });
Nils Diewalda297f062015-04-02 00:23:46 +0000591 });
Nils Diewalda297f062015-04-02 00:23:46 +0000592
593
Akron671fdb92017-09-12 18:09:46 +0200594 describe('KorAP.MatchRelation', function () {
595 var relClass = require('match/relations')
596
597 var relExample = "<span class=\"context-left\"></span>" +
598 "<span class=\"match\">" +
599 " <span xml:id=\"token-GOE/AGA/01784-p199\">" +
600 " <span xlink:title=\"malt/d:ADV\" " +
601 " xlink:type=\"simple\" " +
602 " xlink:href=\"#token-GOE/AGA/01784-p199\">dann</span>" +
603 " </span>" +
604 " zog " +
605 " <span xlink:title=\"malt/d:SUBJ\" " +
606 " xlink:type=\"simple\" " +
607 " xlink:href=\"#token-GOE/AGA/01784-p199\">ich</span>" +
608 " <span xml:id=\"token-GOE/AGA/01784-p202\">" +
609 " <span xlink:title=\"malt/d:OBJA\" " +
610 " xlink:type=\"simple\" " +
611 " xlink:href=\"#token-GOE/AGA/01784-p199\">mich</span>" +
612 " </span>" +
613 "</span>" +
614 "<span class=\"context-right\"></span>";
615
616
617 it('should be initializable', function () {
618 var tree = relClass.create();
619 expect(tree.size()).toBe(0);
620 });
621
622 it('should be parse string data', function () {
623 var tree = relClass.create(relExample);
624 expect(tree.size()).toBe(4);
625 });
626
627
628 });
629
630
Nils Diewald7c8ced22015-04-15 19:21:00 +0000631 describe('KorAP.MatchTreeMenu', function () {
632 var matchTreeMenu = require('match/treemenu');
633 var matchTreeItem = require('match/treeitem');
634
635 it('should be initializable', function () {
636 var menu = matchTreeMenu.create(undefined, [
Akron671fdb92017-09-12 18:09:46 +0200637 ['cnx/c', 'cnx', 'c'],
638 ['xip/c', 'xip', 'c']
Nils Diewald7c8ced22015-04-15 19:21:00 +0000639 ]);
640
641 expect(menu.itemClass()).toEqual(matchTreeItem);
642 expect(menu.element().nodeName).toEqual('UL');
Akronaba7a5a2016-08-15 21:58:33 +0200643 expect(menu.element().classList.contains('visible')).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000644 expect(menu.limit()).toEqual(6);
645 menu.show();
Akronaba7a5a2016-08-15 21:58:33 +0200646 expect(menu.element().classList.contains('visible')).toBeTruthy();
Akronc1457bf2015-06-11 19:24:00 +0200647 expect(menu.item(0).active()).toBe(false);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000648 });
Nils Diewalda297f062015-04-02 00:23:46 +0000649 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000650
651 // table = view.toTable();
652 // table.sortBy('');
653 // table.element();
654 // tree = view.toTree();
655 // tree.element();
Nils Diewalda297f062015-04-02 00:23:46 +0000656});