blob: a60d7ab9ba7996591cff3e9e197e6216e9cf9e33 [file] [log] [blame]
Akronaba7a5a2016-08-15 21:58:33 +02001define(
2 ['menu', 'menu/item', 'menu/prefix', 'menu/lengthField'],
3 function (menuClass, menuItemClass, prefixClass, lengthFieldClass) {
Akron1ff3ac22016-04-28 16:30:45 +02004
Akronaba7a5a2016-08-15 21:58:33 +02005 // The OwnMenu item
6 KorAP.OwnMenuItem = {
7 create : function (params) {
8 return Object.create(menuItemClass).upgradeTo(KorAP.OwnMenuItem)._init(params);
9 },
10 content : function (content) {
11 if (arguments.length === 1) {
12 this._content = content;
13 };
14 return this._content;
15 },
16 _init : function (params) {
17 if (params[0] === undefined)
18 throw new Error("Missing parameters");
Nils Diewald7c8ced22015-04-15 19:21:00 +000019
Akronaba7a5a2016-08-15 21:58:33 +020020 this._content = document.createTextNode(params[0]);
21 this._lcField = ' ' + this.content().textContent.toLowerCase();
Nils Diewald7c8ced22015-04-15 19:21:00 +000022
Akronaba7a5a2016-08-15 21:58:33 +020023 return this;
24 }
25 };
Nils Diewald7c8ced22015-04-15 19:21:00 +000026
Akronaba7a5a2016-08-15 21:58:33 +020027 // The OwnMenu
28 KorAP.OwnMenu = {
29 create : function (list) {
30 return Object.create(menuClass)
31 .upgradeTo(KorAP.OwnMenu)
32 ._init(list, { itemClass : KorAP.OwnMenuItem });
33 }
34 };
Nils Diewaldfda29d92015-01-22 17:28:01 +000035
Nils Diewaldfda29d92015-01-22 17:28:01 +000036
Akronaba7a5a2016-08-15 21:58:33 +020037 // HintMenuItem
38 KorAP.HintMenuItem = {
39 create : function (params) {
40 return Object.create(menuItemClass)
41 .upgradeTo(KorAP.HintMenuItem)
42 ._init(params);
43 },
44 content : function (content) {
45 if (arguments.length === 1) {
46 this._content = content;
47 };
48 return this._content;
49 },
50 _init : function (params) {
51 if (params[0] === undefined || params[1] === undefined)
52 throw new Error("Missing parameters");
Nils Diewald7c8ced22015-04-15 19:21:00 +000053
Akronaba7a5a2016-08-15 21:58:33 +020054 this._name = params[0];
55 this._action = params[1];
56 this._lcField = ' ' + this._name.toLowerCase();
Nils Diewald7c8ced22015-04-15 19:21:00 +000057
Akronaba7a5a2016-08-15 21:58:33 +020058 if (params.length > 2) {
59 this._desc = params[2];
60 this._lcField += " " + this._desc.toLowerCase();
61 };
62
63 return this;
64 },
Nils Diewald7c8ced22015-04-15 19:21:00 +000065
Akronaba7a5a2016-08-15 21:58:33 +020066 name : function () {
67 return this._name;
68 },
69 action : function () {
70 return this._action;
71 },
72 desc : function () {
73 return this._desc;
74 },
75 element : function () {
76 // already defined
77 if (this._element !== undefined)
78 return this._element;
Nils Diewald7c8ced22015-04-15 19:21:00 +000079
Akronaba7a5a2016-08-15 21:58:33 +020080 // Create list item
81 var li = document.createElement("li");
82 li.setAttribute("data-action", this._action);
Nils Diewald7c8ced22015-04-15 19:21:00 +000083
Akronaba7a5a2016-08-15 21:58:33 +020084 // Create title
85 var name = document.createElement("strong");
86 name.appendChild(document.createTextNode(this._name));
87
88 li.appendChild(name);
Nils Diewald7c8ced22015-04-15 19:21:00 +000089
Akronaba7a5a2016-08-15 21:58:33 +020090 // Create description
91 if (this._desc !== undefined) {
92 var desc = document.createElement("span");
93 desc.appendChild(document.createTextNode(this._desc));
94 li.appendChild(desc);
95 };
96 return this._element = li;
97 }
98 };
99
100
101 // HintMenu
102 KorAP.HintMenu = {
103 create : function (context, list) {
104 var obj = Object.create(menuClass)
105 .upgradeTo(KorAP.HintMenu)
106 ._init(list, {itemClass : KorAP.HintMenuItem});
107 obj._context = context;
108 return obj;
109 }
110 };
111
112
113 // The ComplexMenuItem
114 KorAP.ComplexMenuItem = {
115 create : function (params) {
116 return Object.create(menuItemClass)
117 .upgradeTo(KorAP.ComplexMenuItem)
118 ._init(params);
119 },
120 content : function (content) {
121 if (arguments.length === 1) {
122 this._content = content;
123 };
124 return this._content;
125 },
126 _init : function (params) {
127 if (params[0] === undefined)
128 throw new Error("Missing parameters");
129
130 var r = document.createElement('div');
131 for (var i = 1; i <= params.length; i++) {
132 var h = document.createElement('h' + i);
133 h.appendChild(document.createTextNode(params[i-1]));
134 r.appendChild(h);
135 };
136
137 this._content = r;
138 this._lcField = ' ' + this.content().textContent.toLowerCase();
139
140 return this;
141 }
142 };
143
144
145 describe('KorAP.MenuItem', function () {
146 it('should be initializable', function () {
147 expect(
148 function() { menuItemClass.create([]) }
149 ).toThrow(new Error("Missing parameters"));
150
151 expect(
152 function() { KorAP.OwnMenuItem.create([]) }
153 ).toThrow(new Error("Missing parameters"));
154
155 var mi = KorAP.OwnMenuItem.create(["Baum"]);
156 expect(mi.element().firstChild.nodeValue).toEqual('Baum');
157 expect(mi.lcField()).toEqual(' baum');
158 });
159
160 it('shouldn\'t have a reference to the menu', function () {
161 var menuItem = KorAP.OwnMenuItem.create(['Test']);
162 expect(menuItem.menu()).toBe(undefined);
163 });
164
165 it('should be activatable and deactivateable by class', function () {
166 var menuItem = KorAP.OwnMenuItem.create(['Test']);
167
168 expect(menuItem.active()).toBe(false);
169 expect(menuItem.element().getAttribute("class")).toBe(null);
170 menuItem.active(true);
171 expect(menuItem.active()).toBe(true);
172 expect(menuItem.element().getAttribute("class")).toEqual("active");
173 menuItem.active(false); // Is active
174 expect(menuItem.active()).toBe(false);
175 expect(menuItem.element().getAttribute("class")).toEqual("");
176 menuItem.active(true);
177 expect(menuItem.active()).toBe(true);
178 expect(menuItem.element().getAttribute("class")).toEqual("active");
179
180 menuItem = KorAP.OwnMenuItem.create(['Spiegel']);
181 expect(menuItem.active()).toBe(false);
182 expect(menuItem.element().getAttribute("class")).toBe(null);
183 menuItem.active(false); // Is not active
184 expect(menuItem.active()).toBe(false);
185 expect(menuItem.element().getAttribute("class")).toBe(null);
186 });
187
188 it('should be set to boundary', function () {
189 var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']);
190 expect(menuItem.active()).toBe(false);
191 expect(menuItem.element().getAttribute("class")).toBe(null);
192
193 // Set active
194 menuItem.active(true);
195 expect(menuItem.active()).toBe(true);
196 expect(menuItem.noMore()).toBe(false);
197 expect(menuItem.element().getAttribute("class")).toEqual("active");
198
199 // Set no more
200 menuItem.noMore(true);
201 expect(menuItem.active()).toBe(true);
202 expect(menuItem.noMore()).toBe(true);
203 expect(menuItem.element().getAttribute("class")).toEqual("active no-more");
204
205 // No no more
206 menuItem.noMore(false);
207 expect(menuItem.active()).toBe(true);
208 expect(menuItem.noMore()).toBe(false);
209 expect(menuItem.element().getAttribute("class")).toEqual("active");
210
211 // Set no more, deactivate
212 menuItem.noMore(true);
213 menuItem.active(false);
214 expect(menuItem.active()).toBe(false);
215 expect(menuItem.noMore()).toBe(true);
216 expect(menuItem.element().getAttribute("class")).toEqual("no-more");
217
218 // Set active
219 menuItem.active(true);
220 expect(menuItem.active()).toBe(true);
221 expect(menuItem.noMore()).toBe(true);
222 expect(menuItem.element().getAttribute("class")).toEqual("no-more active");
223 });
224
225
226 it('should be highlightable', function () {
227 // Highlight in the middle
228 var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']);
229 menuItem.highlight("ren");
230 expect(menuItem.element().innerHTML).toEqual("Co<mark>reN</mark>LP");
231
232 menuItem.lowlight();
233 expect(menuItem.element().innerHTML).toEqual("CoreNLP");
234
235 var plain = "<div><h1>CoreNLP</h1><h2>corenlp/</h2></div>";
236
237 // Starting highlight
238 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
239 menuItem.highlight("cor");
240 expect(menuItem.element().innerHTML).toEqual("<div><h1><mark>Cor</mark>eNLP</h1><h2><mark>cor</mark>enlp/</h2></div>");
241
242 menuItem.lowlight();
243 expect(menuItem.element().innerHTML).toEqual(plain);
244
245 // Starting highlight - short
246 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
247 menuItem.highlight("c");
248 expect(menuItem.element().innerHTML).toEqual("<div><h1><mark>C</mark>oreNLP</h1><h2><mark>c</mark>orenlp/</h2></div>");
249
250 menuItem.lowlight();
251 expect(menuItem.element().innerHTML).toEqual(plain);
252
253 // Highlight at the end
254 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
255 menuItem.highlight("nlp");
256 expect(menuItem.element().innerHTML).toEqual("<div><h1>Core<mark>NLP</mark></h1><h2>core<mark>nlp</mark>/</h2></div>");
257
258 menuItem.lowlight();
259 expect(menuItem.element().innerHTML).toEqual(plain);
260
261 // Highlight at the end - short
262 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
263 menuItem.highlight("p");
264 expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNL<mark>P</mark></h1><h2>corenl<mark>p</mark>/</h2></div>");
265
266 menuItem.lowlight();
267 expect(menuItem.element().innerHTML).toEqual(plain);
268
269 // No highlight
270 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
271 menuItem.highlight("xp");
272 expect(menuItem.element().innerHTML).toEqual(plain);
273
274 menuItem.lowlight();
275 expect(menuItem.element().innerHTML).toEqual(plain);
276
277 // Highlight in the middle - first
278 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
279 menuItem.highlight("ren");
280 expect(menuItem.element().innerHTML).toEqual("<div><h1>Co<mark>reN</mark>LP</h1><h2>co<mark>ren</mark>lp/</h2><h3>This is my Example</h3></div>");
281
282 plain = "<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Example</h3></div>"
283
284 menuItem.lowlight();
285 expect(menuItem.element().innerHTML).toEqual(plain);
286
287 // Highlight in the middle - second
288 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
289 menuItem.highlight("ampl");
290 expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Ex<mark>ampl</mark>e</h3></div>");
291
292 menuItem.lowlight();
293 expect(menuItem.element().innerHTML).toEqual(plain);
294
295 // Highlight in the middle - both
296 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
297 menuItem.highlight("e");
Akronacffc652017-12-18 21:21:25 +0100298
Akronaba7a5a2016-08-15 21:58:33 +0200299 expect(menuItem.element().innerHTML).toEqual("<div><h1>Cor<mark>e</mark>NLP</h1><h2>cor<mark>e</mark>nlp/</h2><h3>This is my <mark>E</mark>xampl<mark>e</mark></h3></div>");
300
301 menuItem.lowlight();
302 expect(menuItem.element().innerHTML).toEqual(plain);
303
304 // Highlight in the end - second
305 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
306 menuItem.highlight("le");
307 expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Examp<mark>le</mark></h3></div>");
308
309 menuItem.lowlight();
310 expect(menuItem.element().innerHTML).toEqual(plain);
311
312 // Highlight at the beginning - second
313 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
314 menuItem.highlight("this");
315 expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3><mark>This</mark> is my Example</h3></div>");
316
317 menuItem.lowlight();
318 expect(menuItem.element().innerHTML).toEqual(plain);
319 });
320 });
321
322
323 describe('KorAP.Menu', function () {
324 var list = [
325 ["Constituency", "c=", "Example 1"],
326 ["Lemma", "l="],
327 ["Morphology", "m=", "Example 2"],
328 ["Part-of-Speech", "p="],
329 ["Syntax", "syn="]
330 ];
331
Akronacffc652017-12-18 21:21:25 +0100332 var listMultiPrefix = [
333 ["PP","PP ","Personal Pronoun"],
334 ["PPP","PPP ","Personal Pronoun, Plural"],
335 ["PPPA","PPPA ","Personal Pronoun, Plural, Acc."],
336 ["PPPD","PPPD ","Personal Pronoun, Plural, Dative"],
337 ["PPPR","PPPR ","Personal Pronoun, Plural, Direct"],
338 ["PPPO","PPPO ","Personal Pronoun, Plural, Oblique"],
339 ["PPS","PPS ","Personal Pronoun, Singular"],
340 ["PPSA","PPSA ","Personal Pronoun, Singular, Accusative"],
341 ["PPSD","PPSD ","Personal Pronoun, Singular, Dative"],
342 ["PPSR","PPSR ","Personal Pronoun, Singular, Direct"],
343 ["PPSN","PPSN ","Personal Pronoun, Singular, Nominative"],
344 ["PPSO","PPSO ","Personal Pronoun, Singular, Oblique"]
345 ];
346
Akronaba7a5a2016-08-15 21:58:33 +0200347 var demolist = [
348 ['Titel', 'title'],
349 ['Untertitel', 'subTitle'],
350 ['Veröffentlichungsdatum', 'pubDate'],
351 ['Länge', 'length'],
352 ['Autor', 'author']
353 ];
354
355 var demolonglist = [
356 ['Titel', 'title'],
357 ['Untertitel', 'subTitle'],
358 ['Veröffentlichungsdatum', 'pubDate'],
359 ['Länge', 'length'],
360 ['Autor', 'author'],
361 ['Genre', 'genre'],
362 ['corpusID', 'corpusID'],
363 ['docID', 'docID'],
364 ['textID', 'textID'],
365 ];
366
367 it('should be initializable', function () {
368 var list = [
369 ["Constituency"],
370 ["Lemma"],
371 ["Morphology"],
372 ["Part-of-Speech"],
373 ["Syntax"]
374 ];
375
376 var menu = KorAP.OwnMenu.create(list);
377 menu._firstActive = true;
378 expect(menu.itemClass()).toEqual(KorAP.OwnMenuItem);
379 expect(menu.element().nodeName).toEqual('UL');
380 expect(menu.element().classList.contains('visible')).toBeFalsy();
381 expect(menu.limit()).toEqual(8);
382
383 menu.limit(9);
384 expect(menu.limit()).toEqual(9);
385
386 menu.limit(8);
387
388 // view
389 menu.show();
390
391 // First element in list
392 expect(menu.item(0).active()).toBe(true);
393 expect(menu.item(0).noMore()).toBe(true);
394
395 // Middle element in list
396 expect(menu.item(2).active()).toBe(false);
397 expect(menu.item(2).noMore()).toBe(false);
398
399 // Last element in list
400 expect(menu.item(menu.length() - 1).active()).toBe(false);
401 expect(menu.item(menu.length() - 1).noMore()).toBe(true);
402 });
403
404 it('should have a reference to the menu', function () {
405 var menu = KorAP.HintMenu.create("cnx/", list);
406 expect(menu.item(0).menu()).toEqual(menu);
407
408 menu = KorAP.HintMenu.create("cnx/", list);
409 expect(menu.element().menu).toEqual(menu);
410 });
411
412
413 it('should be visible', function () {
414 var menu = KorAP.HintMenu.create("cnx/", list);
415 expect(menu.removeItems()).toBe(undefined);
416 menu.limit(3);
417
418 expect(menu.show()).toBe(true);
419
420 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
421 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>");
422 expect(menu.element().childNodes[4].getAttribute("data-action")).toEqual("l=");
423 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
424 expect(menu.element().childNodes[6]).toBe(undefined);
425
426 // Check boundaries
427 expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(true);
428 expect(menu.element().childNodes[4].classList.contains("no-more")).toBe(false);
429 expect(menu.element().childNodes[5].classList.contains("no-more")).toBe(false);
430 });
431
432 it('should be filterable', function () {
433 var menu = KorAP.HintMenu.create("cnx/", list);
434 menu.limit(3);
435 expect(menu.prefix("o").show()).toBe(true);
436 expect(menu.element().childNodes[0].innerHTML).toEqual("o");
437 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
438 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
439 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
440 expect(menu.element().childNodes[6]).toBe(undefined);
441
442 // Check boundaries
443 expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(true);
444 expect(menu.element().childNodes[4].classList.contains("no-more")).toBe(false);
445 expect(menu.element().childNodes[5].classList.contains("no-more")).toBe(true);
446
447 menu.limit(2);
448
449 expect(menu.prefix("o").show()).toBe(true);
450 expect(menu.element().childNodes[0].innerHTML).toEqual("o");
451 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
452 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
453 expect(menu.element().childNodes[5]).toBe(undefined);
454
455 // Check boundaries
456 expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(true);
457 expect(menu.element().childNodes[4].classList.contains("no-more")).toBe(false);
458 expect(menu.element().childNodes[5]).toBe(undefined);
459
460 expect(menu.prefix("e").show()).toBe(true);
461 expect(menu.element().childNodes[0].innerHTML).toEqual("e");
462 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
463 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
464 expect(menu.element().childNodes[5]).toBe(undefined);
465
466 menu.limit(5);
467 expect(menu.prefix("a").show()).toBe(true);
468 expect(menu.element().childNodes[0].innerHTML).toEqual("a");
469 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Ex<mark>a</mark>mple 1</span>");
470 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemm<mark>a</mark></strong>");
471 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Ex<mark>a</mark>mple 2</span>");
472 expect(menu.element().childNodes[6].innerHTML).toEqual("<strong>P<mark>a</mark>rt-of-Speech</strong>");
473 expect(menu.element().childNodes[7].innerHTML).toEqual("<strong>Synt<mark>a</mark>x</strong>");
474 expect(menu.element().childNodes[8]).toBe(undefined);
475 });
476
477
478 it('should be nextable', function () {
479 var menu = KorAP.HintMenu.create("cnx/", list);
480 menu._firstActive = true;
481
482 // Show only 3 items
483 menu.limit(3);
484 expect(menu.show()).toBe(true);
485 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
486 expect(menu.shownItem(0).active()).toBe(true);
487 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>");
488 expect(menu.shownItem(1).active()).toBe(false);
489 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
490 expect(menu.shownItem(2).active()).toBe(false);
491 expect(menu.element().childNodes[6]).toBe(undefined);
492
493 // Activate next (1)
494 menu.next();
495 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
496 expect(menu.shownItem(0).active()).toBe(false);
497 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>");
498 expect(menu.shownItem(1).active()).toBe(true);
499 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
500 expect(menu.shownItem(2).active()).toBe(false);
501 expect(menu.element().childNodes[6]).toBe(undefined);
502
503 // Activate next (2)
504 menu.next();
505 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
506 expect(menu.shownItem(0).active()).toBe(false);
507 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>");
508 expect(menu.shownItem(1).active()).toBe(false);
509 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
510 expect(menu.shownItem(2).active()).toBe(true);
511 expect(menu.element().childNodes[6]).toBe(undefined);
512
513 // Activate next (3)
514 // scroll!
515 menu.next();
516 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Lemma</strong>");
517 expect(menu.shownItem(0).active()).toBe(false);
518 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
519 expect(menu.shownItem(1).active()).toBe(false);
520 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
521 expect(menu.shownItem(2).active()).toBe(true);
522 expect(menu.element().childNodes[6]).toBe(undefined);
523
524 // Activate next (4)
525 menu.next();
526 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
527 expect(menu.shownItem(0).active()).toBe(false);
528 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
529 expect(menu.shownItem(1).active()).toBe(false);
530 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Syntax</strong>");
531 expect(menu.shownItem(2).active()).toBe(true);
532 expect(menu.element().childNodes[6]).toBe(undefined);
533
534 // Activate next (5) - ROLL
535 menu.next();
536 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
537 expect(menu.shownItem(0).active()).toBe(true);
538 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>");
539 expect(menu.shownItem(1).active()).toBe(false);
540 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
541 expect(menu.shownItem(2).active()).toBe(false);
542 expect(menu.element().childNodes[6]).toBe(undefined);
543
544 // Active next (6)
545 menu.next();
546 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
547 expect(menu.shownItem(0).active()).toBe(false);
548 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>");
549 expect(menu.shownItem(1).active()).toBe(true);
550 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
551 expect(menu.shownItem(2).active()).toBe(false);
552 expect(menu.element().childNodes[6]).toBe(undefined);
553 });
554
555 it('should be nextable without active field', function () {
556 var menu = KorAP.HintMenu.create("cnx/", list);
557 menu.limit(3);
558 expect(menu.show()).toBe(true);
559 menu.next();
560 expect(menu.shownItem(0).active()).toEqual(true);
561 });
562
563
564 it('should be prevable', function () {
565 var menu = KorAP.HintMenu.create("cnx/", list);
566 menu._firstActive = true;
567 menu.limit(3);
568 expect(menu.show()).toBe(true);
569
570 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
571 expect(menu.shownItem(0).active()).toBe(true);
572 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>");
573 expect(menu.shownItem(1).active()).toBe(false);
574 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
575 expect(menu.shownItem(2).active()).toBe(false);
576 expect(menu.element().childNodes[6]).toBe(undefined);
577
578 // Activate prev (1) - roll to bottom
579 menu.prev();
580 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
581 expect(menu.shownItem(0).active()).toBe(false);
582 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
583 expect(menu.shownItem(1).active()).toBe(false);
584 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Syntax</strong>");
585 expect(menu.shownItem(2).active()).toBe(true);
586 expect(menu.element().childNodes[6]).toBe(undefined);
587
588 // Activate prev (2)
589 menu.prev();
590 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
591 expect(menu.shownItem(0).active()).toBe(false);
592 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
593 expect(menu.shownItem(1).active()).toBe(true);
594 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Syntax</strong>");
595 expect(menu.shownItem(2).active()).toBe(false);
596 expect(menu.element().childNodes[6]).toBe(undefined);
597
598 // Activate prev (3)
599 menu.prev();
600 expect(menu.shownItem(0).name()).toEqual("Morphology");
601 expect(menu.shownItem(0).active()).toBe(true);
602 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
603 expect(menu.shownItem(1).active()).toBe(false);
604 expect(menu.shownItem(2).name()).toEqual("Syntax");
605 expect(menu.shownItem(2).active()).toBe(false);
606 expect(menu.element().childNodes[6]).toBe(undefined);
607
608 // Activate prev (4)
609 menu.prev();
610 expect(menu.shownItem(0).name()).toEqual("Lemma");
611 expect(menu.shownItem(0).active()).toBe(true);
612 expect(menu.shownItem(1).name()).toEqual("Morphology");
613 expect(menu.shownItem(1).active()).toBe(false);
614 expect(menu.shownItem(2).name()).toEqual("Part-of-Speech");
615 expect(menu.shownItem(2).active()).toBe(false);
616 expect(menu.element().childNodes[6]).toBe(undefined);
617
618 // Activate prev (5)
619 menu.prev();
620 expect(menu.shownItem(0).name()).toEqual("Constituency");
621 expect(menu.shownItem(0).active()).toBe(true);
622 expect(menu.shownItem(1).name()).toEqual("Lemma");
623 expect(menu.shownItem(1).active()).toBe(false);
624 expect(menu.shownItem(2).name()).toEqual("Morphology");
625 expect(menu.shownItem(2).active()).toBe(false);
626 expect(menu.element().childNodes[6]).toBe(undefined);
627
628 // Activate next (1)
629 menu.next();
630 expect(menu.shownItem(0).name()).toEqual("Constituency");
631 expect(menu.shownItem(0).active()).toBe(false);
632 expect(menu.shownItem(1).name()).toEqual("Lemma");
633 expect(menu.shownItem(1).active()).toBe(true);
634 expect(menu.shownItem(2).name()).toEqual("Morphology");
635 expect(menu.shownItem(2).active()).toBe(false);
636 expect(menu.element().childNodes[6]).toBe(undefined);
637
638 // Activate prev (6)
639 menu.prev();
640
641 // Activate prev (7)
642 menu.prev();
643 expect(menu.shownItem(0).name()).toEqual("Morphology");
644 expect(menu.shownItem(0).active()).toBe(false);
645 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
646 expect(menu.shownItem(1).active()).toBe(false);
647 expect(menu.shownItem(2).name()).toEqual("Syntax");
648 expect(menu.shownItem(2).active()).toBe(true);
649 expect(menu.element().childNodes[6]).toBe(undefined);
650 });
651
652 it('should be prevable without active field', function () {
653 var menu = KorAP.HintMenu.create("cnx/", list);
654 menu.limit(3);
655 expect(menu.show()).toBe(true);
656 menu.prev();
657 expect(menu.shownItem(2).active()).toEqual(true);
658 expect(menu.shownItem(2).lcField()).toEqual(' syntax');
659 });
660
661 it('should be navigatable and filterable (prefix = "o")', function () {
662 var menu = KorAP.HintMenu.create("cnx/", list);
663 menu._firstActive = true;
664 menu.limit(2);
665
666 expect(menu.prefix("o").show()).toBe(true);
667 expect(menu.shownItem(0).name()).toEqual("Constituency");
668 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
669 expect(menu.shownItem(0).active()).toBe(true);
670 expect(menu.shownItem(1).name()).toEqual("Morphology");
671 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
672 expect(menu.shownItem(1).active()).toBe(false);
673 expect(menu.shownItem(2)).toBe(undefined);
674
675 // Next (1)
676 menu.next();
677 expect(menu.shownItem(0).name()).toEqual("Constituency");
678 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
679 expect(menu.shownItem(0).active()).toBe(false);
680 expect(menu.shownItem(1).name()).toEqual("Morphology");
681 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
682 expect(menu.shownItem(1).active()).toBe(true);
683 expect(menu.shownItem(2)).toBe(undefined);
684
685 // Next (2)
686 menu.next();
687 expect(menu.shownItem(0).name()).toEqual("Morphology");
688 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
689 expect(menu.shownItem(0).active()).toBe(false);
690 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
691 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
692 expect(menu.shownItem(1).active()).toBe(true);
693 expect(menu.shownItem(2)).toBe(undefined);
694
695 // Next (3) - to prefix
696 menu.next();
697 expect(menu.shownItem(0).name()).toEqual("Morphology");
698 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
699 expect(menu.shownItem(0).active()).toBe(false);
700 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
701 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
702 expect(menu.shownItem(1).active()).toBe(false);
703 expect(menu.shownItem(2)).toBe(undefined);
704
705 menu.next();
706 expect(menu.shownItem(0).name()).toEqual("Constituency");
707 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
708 expect(menu.shownItem(0).active()).toBe(true);
709 expect(menu.shownItem(1).name()).toEqual("Morphology");
710 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
711 expect(menu.shownItem(1).active()).toBe(false);
712 expect(menu.shownItem(2)).toBe(undefined);
713 });
714
715
716 it('should be navigatable and filterable (prefix = "ex", "e")', function () {
717 var menu = KorAP.HintMenu.create("cnx/", list);
718 menu._firstActive = true;
719
720 menu.limit(2);
721 expect(menu.prefix("ex").show()).toBe(true);
722
723 expect(menu.shownItem(0).name()).toEqual("Constituency");
724 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
725 expect(menu.shownItem(0).active()).toBe(true);
726 expect(menu.shownItem(1).name()).toEqual("Morphology");
727 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
728 expect(menu.shownItem(1).active()).toBe(false);
729 expect(menu.shownItem(2)).toBe(undefined);
730
731 // Next (1)
732 menu.next();
733 expect(menu.shownItem(0).name()).toEqual("Constituency");
734 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
735 expect(menu.shownItem(0).active()).toBe(false);
736 expect(menu.shownItem(1).name()).toEqual("Morphology");
737 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
738 expect(menu.shownItem(1).active()).toBe(true);
739 expect(menu.shownItem(2)).toBe(undefined);
740
741 // Next (2)
742 menu.next();
743
744 expect(menu.prefix()).toEqual('ex');
745 expect(menu.shownItem(0).name()).toEqual("Constituency");
746 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
747 expect(menu.shownItem(0).active()).toBe(false);
748
749 expect(menu.shownItem(1).name()).toEqual("Morphology");
750 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
751 expect(menu.shownItem(1).active()).toBe(false);
752 expect(menu.shownItem(2)).toBe(undefined);
753
754 // Reset limit
755 menu.limit(5);
756
757 // Change show
758 expect(menu.prefix("e").show()).toBe(true);
759 expect(menu._prefix.active()).toBe(false);
760 expect(menu.shownItem(0).name()).toEqual("Constituency");
761 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
762 expect(menu.shownItem(0).active()).toBe(true);
763 expect(menu.shownItem(1).name()).toEqual("Morphology");
764 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
765 expect(menu.shownItem(1).active()).toBe(false);
766 expect(menu.shownItem(2)).toBe(undefined);
767
768 // Next (1)
769 menu.next();
770 expect(menu._prefix.active()).toBe(false);
771 expect(menu.prefix()).toEqual('e');
772 expect(menu.shownItem(0).name()).toEqual("Constituency");
773 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
774 expect(menu.shownItem(0).active()).toBe(false);
775 expect(menu.shownItem(1).name()).toEqual("Morphology");
776 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
777 expect(menu.shownItem(1).active()).toBe(true);
778 expect(menu.shownItem(2)).toBe(undefined);
779
780 // Next (2)
781 menu.next();
782 expect(menu._prefix.active()).toBe(true);
783 expect(menu.shownItem(0).name()).toEqual("Constituency");
784 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
785 expect(menu.shownItem(0).active()).toBe(false);
786 expect(menu.shownItem(1).name()).toEqual("Morphology");
787 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
788 expect(menu.shownItem(1).active()).toBe(false);
789 expect(menu.shownItem(2)).toBe(undefined);
790
791 // Next (3)
792 menu.next();
793 expect(menu._prefix.active()).toBe(false);
794 expect(menu.shownItem(0).name()).toEqual("Constituency");
795 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
796 expect(menu.shownItem(0).active()).toBe(true);
797 expect(menu.shownItem(1).name()).toEqual("Morphology");
798 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
799 expect(menu.shownItem(1).active()).toBe(false);
800 expect(menu.shownItem(2)).toBe(undefined);
801 });
802
Akronacffc652017-12-18 21:21:25 +0100803 it('should be filterable (multiple prefix = "pro sin")', function () {
804 var menu = KorAP.HintMenu.create("drukola/p=", listMultiPrefix);
805 menu._firstActive = true;
806
807 menu.limit(2);
808 expect(menu.prefix("pro sin").show()).toBe(true);
809 expect(menu.shownItem(0).name()).toEqual("PPS");
810 expect(menu.element().childNodes[3].innerHTML).toEqual(
811 "<strong>PPS</strong><span>Personal <mark>Pro</mark>noun, <mark>Sin</mark>gular</span>"
812 );
813
814 expect(menu.shownItem(0).active()).toBe(true);
815 expect(menu.shownItem(1).name()).toEqual("PPSA");
816 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>PPSA</strong><span>Personal <mark>Pro</mark>noun, <mark>Sin</mark>gular, Accusative</span>");
817 expect(menu.shownItem(1).active()).toBe(false);
818
819 expect(menu.shownItem(2)).toBe(undefined);
820 });
Akronaba7a5a2016-08-15 21:58:33 +0200821
Akron359c7e12017-12-19 12:06:55 +0100822 it('should be filterable (trimming = " p")', function () {
823 var menu = KorAP.HintMenu.create("/p=", listMultiPrefix);
824 // menu._firstActive = true;
825
826 menu.limit(2);
827 expect(menu.show()).toBe(true);
828 menu._prefix.add(" ");
829 expect(menu.show()).toBe(true);
830 menu._prefix.add("p")
831 expect(menu.show()).toBe(true);
832 expect(menu.shownItem(0).name()).toEqual("PP");
833 expect(menu.element().childNodes[3].innerHTML).toEqual(
834 "<strong><mark>P</mark><mark>P</mark></strong>"+
835 "<span><mark>P</mark>ersonal <mark>P</mark>ronoun</span>"
836 );
837 });
838
839
Akronaba7a5a2016-08-15 21:58:33 +0200840 it('should choose prefix with failing prefix (1)', function () {
841 var menu = KorAP.HintMenu.create("cnx/", list);
842 menu.limit(2);
843 expect(menu.prefix("exit").show()).toBe(true);
844 expect(menu.element().querySelector('li')).toBe(null);
845 expect(menu.shownItem(0)).toBeUndefined();
846 expect(menu._prefix.active()).toBe(true);
847 });
848
849
850 it('should choose prefix with failing prefix (2)', function () {
851 var menu = KorAP.HintMenu.create("cnx/", list);
852 menu.limit(2);
853 expect(menu.show()).toBe(true);
854 expect(menu.prefix("exit").show()).toBe(true);
855 expect(menu.element().querySelector('li')).toBe(null);
856 expect(menu.shownItem(0)).toBeUndefined();
857 expect(menu._prefix.active()).toBe(true);
858 });
859
860 it('should ignore navigation with failing prefix', function () {
861 var menu = KorAP.HintMenu.create("cnx/", list);
862 menu.limit(2);
863 expect(menu.show()).toBe(true);
864
865 menu.next();
866
867 expect(menu.prefix("exit").show()).toBe(true);
868 expect(menu.element().querySelector('li')).toBe(null);
869 expect(menu.shownItem(0)).toBeUndefined();
870 expect(menu._prefix.active()).toBe(true);
871
872 menu.next();
873 expect(menu._prefix.active()).toBe(true);
874
875 menu.prev();
876 expect(menu._prefix.active()).toBe(true);
877
878 });
879
880 it('should be navigatable with prefix', function () {
881 var menu = KorAP.HintMenu.create("cnx/", demolist);
882 menu._firstActive = true;
883
884 menu.limit(3);
885
886 expect(menu.show()).toBe(true);
887 expect(menu.prefix()).toEqual("");
888
889 expect(menu.shownItem(0).name()).toEqual("Titel");
890 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
891 expect(menu.shownItem(0).active()).toBe(true);
892 expect(menu.shownItem(1).name()).toEqual("Untertitel");
893 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
894 expect(menu.shownItem(1).active()).toBe(false);
895 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
896 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
897 expect(menu.shownItem(2).active()).toBe(false);
898 expect(menu.shownItem(3)).toBe(undefined);
899
900 menu._prefix.add('a');
901 expect(menu.show()).toBe(true);
902 expect(menu.prefix()).toEqual("a");
903 expect(menu.shownItem(0).name()).toEqual("Autor");
904 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
905
906 menu._prefix.add('u');
907 expect(menu.show()).toBe(true);
908 expect(menu.prefix()).toEqual("au");
909 expect(menu.shownItem(0).name()).toEqual("Autor");
910 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong><mark>Au</mark>tor</strong>");
911
912 menu._prefix.chop();
913 expect(menu.show()).toBe(true);
914 expect(menu.prefix()).toEqual("a");
915 expect(menu.shownItem(0).name()).toEqual("Autor");
916 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
917
918 menu._prefix.chop();
919 expect(menu.show()).toBe(true);
920 expect(menu.prefix()).toEqual("");
921 expect(menu.shownItem(0).name()).toEqual("Titel");
922 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
923 expect(menu.shownItem(0).active()).toBe(true);
924 expect(menu.shownItem(1).name()).toEqual("Untertitel");
925 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
926 expect(menu.shownItem(1).active()).toBe(false);
927 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
928 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
929 expect(menu.shownItem(2).active()).toBe(false);
930 expect(menu.shownItem(3)).toBe(undefined);
931
932 // Forward
933 menu._prefix.chop();
934 expect(menu.show()).toBe(true);
935 expect(menu.prefix()).toEqual("");
936 expect(menu.shownItem(0).name()).toEqual("Titel");
937 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
938 expect(menu.shownItem(0).active()).toBe(true);
939 expect(menu.shownItem(1).name()).toEqual("Untertitel");
940 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
941 expect(menu.shownItem(1).active()).toBe(false);
942 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
943 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
944 expect(menu.shownItem(2).active()).toBe(false);
945
946 // Forward
947 menu.next();
948 expect(menu.prefix()).toEqual("");
949 expect(menu.shownItem(0).name()).toEqual("Titel");
950 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
951 expect(menu.shownItem(0).active()).toBe(false);
952 expect(menu.shownItem(1).name()).toEqual("Untertitel");
953 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
954 expect(menu.shownItem(1).active()).toBe(true);
955 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
956 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
957 expect(menu.shownItem(2).active()).toBe(false);
958 expect(menu.shownItem(3)).toBe(undefined);
959
960 // Forward
961 menu.next();
962 expect(menu.prefix()).toEqual("");
963 expect(menu.shownItem(0).name()).toEqual("Titel");
964 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
965 expect(menu.shownItem(0).active()).toBe(false);
966 expect(menu.shownItem(1).name()).toEqual("Untertitel");
967 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
968 expect(menu.shownItem(1).active()).toBe(false);
969 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
970 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
971 expect(menu.shownItem(2).active()).toBe(true);
972 expect(menu.shownItem(3)).toBe(undefined);
973
974 // Forward
975 menu.next();
976 expect(menu.prefix()).toEqual("");
977 expect(menu.shownItem(0).name()).toEqual("Untertitel");
978 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Untertitel</strong>");
979 expect(menu.shownItem(0).active()).toBe(false);
980 expect(menu.shownItem(1).name()).toEqual("Veröffentlichungsdatum");
981 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
982 expect(menu.shownItem(1).active()).toBe(false);
983 expect(menu.shownItem(2).name()).toEqual("Länge");
984 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Länge</strong>");
985 expect(menu.shownItem(2).active()).toBe(true);
986 expect(menu.shownItem(3)).toBe(undefined);
987
988 // Forward
989 menu.next();
990 expect(menu.prefix()).toEqual("");
991 expect(menu.shownItem(0).name()).toEqual("Veröffentlichungsdatum");
992 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
993 expect(menu.shownItem(0).active()).toBe(false);
994 expect(menu.shownItem(1).name()).toEqual("Länge");
995 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Länge</strong>");
996 expect(menu.shownItem(1).active()).toBe(false);
997 expect(menu.shownItem(2).name()).toEqual("Autor");
998 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Autor</strong>");
999 expect(menu.shownItem(2).active()).toBe(true);
1000 expect(menu.shownItem(3)).toBe(undefined);
1001
1002 // Forward
1003 menu.next();
1004 expect(menu.prefix()).toEqual("");
1005 expect(menu.shownItem(0).name()).toEqual("Titel");
1006 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
1007 expect(menu.shownItem(0).active()).toBe(true);
1008 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1009 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
1010 expect(menu.shownItem(1).active()).toBe(false);
1011 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
1012 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
1013 expect(menu.shownItem(2).active()).toBe(false);
1014 });
1015
1016
1017 it('should be navigatable with a prefix (1)', function () {
1018 var menu = KorAP.HintMenu.create("cnx/", demolist);
1019 menu._firstActive = true;
1020
1021 menu.limit(3);
1022
1023 expect(menu.show()).toBe(true);
1024 expect(menu.prefix()).toEqual("");
1025
1026 // Add prefix in uppercase - but check in lowercase
1027 menu.prefix('El');
1028 expect(menu.show()).toBe(true);
1029
1030 expect(menu.prefix()).toEqual("El");
1031 expect(menu._prefix.active()).toEqual(false);
1032 expect(menu.shownItem(0).name()).toEqual("Titel");
1033 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1034 expect(menu.shownItem(0).active()).toBe(true);
1035 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1036 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1037 expect(menu.shownItem(1).active()).toBe(false);
1038 expect(menu.shownItem(2)).toBe(undefined);
1039
1040 // Forward
1041 menu.next();
1042 expect(menu.prefix()).toEqual("El");
1043 expect(menu._prefix.active()).toEqual(false);
1044 expect(menu.shownItem(0).name()).toEqual("Titel");
1045 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1046 expect(menu.shownItem(0).active()).toBe(false);
1047 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1048 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1049 expect(menu.shownItem(1).active()).toBe(true);
1050 expect(menu.shownItem(2)).toBe(undefined);
1051
1052 // Forward
1053 menu.next();
1054 expect(menu.prefix()).toEqual("El");
1055 expect(menu._prefix.active()).toEqual(true);
1056 expect(menu.shownItem(0).name()).toEqual("Titel");
1057 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1058 expect(menu.shownItem(0).active()).toBe(false);
1059 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1060 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1061 expect(menu.shownItem(1).active()).toBe(false);
1062 expect(menu.shownItem(2)).toBe(undefined);
1063
1064 // Backward
1065 menu.prev();
1066 expect(menu.prefix()).toEqual("El");
1067 expect(menu._prefix.active()).toEqual(false);
1068 expect(menu.shownItem(0).name()).toEqual("Titel");
1069 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1070 expect(menu.shownItem(0).active()).toBe(false);
1071
1072 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1073 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1074 expect(menu.shownItem(1).active()).toBe(true);
1075 expect(menu.shownItem(2)).toBe(undefined);
1076 });
1077
1078
1079 it('should be navigatable with a prefix (2)', function () {
1080 var menu = KorAP.HintMenu.create("cnx/", demolist);
1081 menu._firstActive = true;
1082
1083 menu.limit(3);
1084 expect(menu.show()).toBe(true);
1085 expect(menu.prefix()).toEqual("");
1086 menu.prefix('el');
1087 expect(menu.show()).toBe(true);
1088
1089 expect(menu.prefix()).toEqual("el");
1090 expect(menu._prefix.active()).toEqual(false);
1091 expect(menu.shownItem(0).name()).toEqual("Titel");
1092 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1093 expect(menu.shownItem(0).active()).toBe(true);
1094 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1095 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1096 expect(menu.shownItem(1).active()).toBe(false);
1097 expect(menu.shownItem(2)).toBe(undefined);
1098
1099 // Backward
1100 menu.prev();
1101 expect(menu._prefix.active()).toEqual(true);
1102
1103 expect(menu.shownItem(0).name()).toEqual("Titel");
1104 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1105 expect(menu.shownItem(0).active()).toBe(false);
1106
1107 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1108 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1109 expect(menu.shownItem(1).active()).toBe(false);
1110 expect(menu.shownItem(2)).toBe(undefined);
1111
1112 // Backward
1113 menu.prev();
1114 expect(menu._prefix.active()).toEqual(false);
1115 expect(menu.shownItem(0).name()).toEqual("Titel");
1116 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1117 expect(menu.shownItem(0).active()).toBe(false);
1118 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1119 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1120 expect(menu.shownItem(1).active()).toBe(true);
1121 expect(menu.shownItem(2)).toBe(undefined);
1122 });
1123
1124 it('should be navigatable with a prefix (3)', function () {
1125 var menu = KorAP.HintMenu.create("cnx/", demolist);
1126 menu._firstActive = true;
1127 menu.limit(3);
1128 expect(menu.show()).toBe(true);
1129 expect(menu.prefix()).toEqual("");
1130 menu.prefix('el');
1131 expect(menu.show()).toBe(true);
1132
1133 expect(menu.prefix()).toEqual("el");
1134 expect(menu._prefix.active()).toEqual(false);
1135 expect(menu.shownItem(0).name()).toEqual("Titel");
1136 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1137 expect(menu.shownItem(0).active()).toBe(true);
1138 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1139 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1140 expect(menu.shownItem(1).active()).toBe(false);
1141 expect(menu.shownItem(2)).toBe(undefined);
1142
1143 // Backward
1144 menu.prev();
1145 expect(menu._prefix.active()).toEqual(true);
1146 expect(menu.shownItem(0).name()).toEqual("Titel");
1147 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1148 expect(menu.shownItem(0).active()).toBe(false);
1149 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1150 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1151 expect(menu.shownItem(1).active()).toBe(false);
1152 expect(menu.shownItem(2)).toBe(undefined);
1153
1154
1155 // Forward
1156 menu.next();
1157 expect(menu.prefix()).toEqual("el");
1158 expect(menu._prefix.active()).toEqual(false);
1159 expect(menu.shownItem(0).name()).toEqual("Titel");
1160 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1161 expect(menu.shownItem(0).active()).toBe(true);
1162 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1163 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1164 expect(menu.shownItem(1).active()).toBe(false);
1165 expect(menu.shownItem(2)).toBe(undefined);
1166
1167 });
1168
1169 it('should show screens by offset', function () {
1170 var menu = KorAP.HintMenu.create('cnx/', demolist);
1171 menu.limit(3);
1172 expect(menu.show()).toBe(true);
1173
1174 expect(menu.shownItem(0).active()).toBe(false);
1175 expect(menu.shownItem(1).active()).toBe(false);
1176 expect(menu.shownItem(2).active()).toBe(false);
1177
1178 // Highlight the first entry
1179 menu.next();
1180
1181 expect(menu.shownItem(0).active()).toBe(true);
1182 expect(menu.shownItem(1).active()).toBe(false);
1183 expect(menu.shownItem(2).active()).toBe(false);
1184
1185 // Highlight the second entry
1186 menu.next();
1187
1188 expect(menu.shownItem(0).active()).toBe(false);
1189 expect(menu.shownItem(1).active()).toBe(true);
1190 expect(menu.shownItem(2).active()).toBe(false);
1191 expect(menu.shownItem(3)).toBe(undefined);
1192
1193 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1194 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1195
1196 // Move to first screen
1197 menu.screen(0);
1198 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1199 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1200 expect(menu.shownItem(0).active()).toBe(false);
1201 expect(menu.shownItem(1).active()).toBe(true);
1202 expect(menu.shownItem(2).active()).toBe(false);
1203 expect(menu.shownItem(3)).toBe(undefined);
1204
1205 // Move to second screen
1206 menu.screen(1);
1207 expect(menu.shownItem(0).lcField()).toEqual(' untertitel');
1208 expect(menu.shownItem(0).active()).toBe(true);
1209 expect(menu.shownItem(1).active()).toBe(false);
1210 expect(menu.shownItem(2).active()).toBe(false);
1211 expect(menu.shownItem(3)).toBe(undefined);
1212
1213 menu.screen(2);
1214 expect(menu.shownItem(0).lcField()).toEqual(' veröffentlichungsdatum');
1215 expect(menu.shownItem(0).active()).toBe(false);
1216 expect(menu.shownItem(1).active()).toBe(false);
1217 expect(menu.shownItem(2).active()).toBe(false);
1218 expect(menu.shownItem(3)).toBe(undefined);
1219
1220 menu.screen(1);
1221 expect(menu.shownItem(0).lcField()).toEqual(' untertitel');
1222 expect(menu.shownItem(0).active()).toBe(true);
1223 expect(menu.shownItem(1).active()).toBe(false);
1224 expect(menu.shownItem(2).active()).toBe(false);
1225 expect(menu.shownItem(3)).toBe(undefined);
1226 });
1227
1228 it('should show screens by offset when prefixed', function () {
1229 var menu = KorAP.HintMenu.create('cnx/', demolist);
1230 menu.limit(3);
1231 expect(menu.prefix("e").show()).toBe(true);
1232 expect(menu.shownItem(0).active()).toBe(false);
1233 expect(menu.shownItem(1).active()).toBe(false);
1234 expect(menu.shownItem(2).active()).toBe(false);
1235
1236 expect(menu.shownItem(0).element().innerHTML).toEqual('<strong>Tit<mark>e</mark>l</strong>');
1237 menu.screen(1);
1238 expect(menu.shownItem(0).element().innerHTML).toEqual('<strong>Unt<mark>e</mark>rtit<mark>e</mark>l</strong>');
1239 });
1240
1241
1242 it('should be page downable', function () {
1243 var menu = KorAP.OwnMenu.create(demolonglist);
1244 menu.limit(3);
1245
1246 expect(menu.show(0)).toBe(true);
1247
1248 expect(menu.shownItem(0).active()).toBe(true);
1249 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1250 expect(menu.shownItem(1).active()).toBe(false);
1251 expect(menu.shownItem(2).active()).toBe(false);
1252 expect(menu.shownItem(3)).toBe(undefined);
1253
1254 menu.pageDown();
1255
1256 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1257 expect(menu.shownItem(0).active()).toBe(false);
1258 expect(menu.shownItem(1).active()).toBe(false);
1259 expect(menu.shownItem(2).active()).toBe(false);
1260
1261 menu.pageDown();
1262
1263 expect(menu.shownItem(0).lcField()).toEqual(' corpusid');
1264 expect(menu.shownItem(0).active()).toBe(false);
1265 expect(menu.shownItem(1).active()).toBe(false);
1266 expect(menu.shownItem(2).active()).toBe(false);
1267
1268 // Doesn't matter
1269 menu.pageDown();
1270
1271 expect(menu.shownItem(0).lcField()).toEqual(' corpusid');
1272 expect(menu.shownItem(0).active()).toBe(false);
1273 expect(menu.shownItem(1).active()).toBe(false);
1274 expect(menu.shownItem(2).active()).toBe(false);
1275 });
1276
1277 it('should be page downable with prefix', function () {
1278 var menu = KorAP.OwnMenu.create(demolonglist);
1279 menu.limit(3);
1280
1281 expect(menu.prefix('e').show(0)).toBe(true);
1282
1283 expect(menu.shownItem(0).active()).toBe(true);
1284 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1285 expect(menu.shownItem(1).active()).toBe(false);
1286 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1287 expect(menu.shownItem(2).active()).toBe(false);
1288 expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum');
1289 expect(menu.shownItem(3)).toBe(undefined);
1290
1291 menu.pageDown();
1292
1293 expect(menu.shownItem(0).active()).toBe(false);
1294 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1295 expect(menu.shownItem(1).active()).toBe(false);
1296 expect(menu.shownItem(1).lcField()).toEqual(' genre');
1297 expect(menu.shownItem(2).active()).toBe(false);
1298 expect(menu.shownItem(2).lcField()).toEqual(' textid');
1299
1300 // Doesn't matter
1301 menu.pageDown();
1302
1303 expect(menu.shownItem(0).active()).toBe(false);
1304 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1305 expect(menu.shownItem(1).active()).toBe(false);
1306 expect(menu.shownItem(1).lcField()).toEqual(' genre');
1307 expect(menu.shownItem(2).active()).toBe(false);
1308 expect(menu.shownItem(2).lcField()).toEqual(' textid');
1309 });
1310
1311
1312 it('should be page upable', function () {
1313 var menu = KorAP.OwnMenu.create(demolonglist);
1314 menu.limit(3);
1315
1316 // Choose the final value
1317 expect(menu.show(1000)).toBe(true);
1318
1319 expect(menu.shownItem(0).active()).toBe(false);
1320 expect(menu.shownItem(1).active()).toBe(false);
1321 expect(menu.shownItem(2).active()).toBe(true);
1322 expect(menu.shownItem(2).lcField()).toEqual(' textid');
1323 expect(menu.shownItem(3)).toBe(undefined);
1324
1325 menu.pageUp();
1326
1327 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1328 expect(menu.shownItem(0).active()).toBe(false);
1329 expect(menu.shownItem(1).active()).toBe(false);
1330 expect(menu.shownItem(2).active()).toBe(false);
1331
1332 menu.pageUp();
1333
1334 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1335 expect(menu.shownItem(0).active()).toBe(false);
1336 expect(menu.shownItem(1).active()).toBe(false);
1337 expect(menu.shownItem(2).active()).toBe(false);
1338
1339 // Doesn't matter
1340 menu.pageUp();
1341
1342 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1343 expect(menu.shownItem(0).active()).toBe(false);
1344 expect(menu.shownItem(1).active()).toBe(false);
1345 expect(menu.shownItem(2).active()).toBe(false);
1346 });
1347
1348 it('should be page upable with prefix', function () {
1349 var menu = KorAP.OwnMenu.create(demolonglist);
1350 menu.limit(3);
1351
1352 // Choose the final value
1353 expect(menu.prefix("e").show(1000)).toBe(true);
1354
1355 expect(menu.shownItem(0).active()).toBe(false);
1356 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1357 expect(menu.shownItem(1).active()).toBe(false);
1358 expect(menu.shownItem(1).lcField()).toEqual(' genre');
1359 expect(menu.shownItem(2).active()).toBe(true);
1360 expect(menu.shownItem(2).lcField()).toEqual(' textid');
1361 expect(menu.shownItem(3)).toBe(undefined);
1362
1363 menu.pageUp();
1364
1365 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1366 expect(menu.shownItem(0).active()).toBe(false);
1367 expect(menu.shownItem(1).active()).toBe(false);
1368 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1369 expect(menu.shownItem(2).active()).toBe(false);
1370 expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum');
1371
1372 // Doesn't matter
1373 menu.pageUp();
1374
1375 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1376 expect(menu.shownItem(0).active()).toBe(false);
1377 expect(menu.shownItem(1).active()).toBe(false);
1378 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1379 expect(menu.shownItem(2).active()).toBe(false);
1380 expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum');
1381 });
1382
1383 it('should scroll to a chosen value (1)', function () {
1384 var menu = KorAP.OwnMenu.create(demolist);
1385 menu.limit(3);
1386
1387 // Choose value 1
1388 expect(menu.show(1)).toBe(true);
1389
1390 expect(menu.shownItem(0).active()).toBe(false);
1391 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1392 expect(menu.shownItem(1).active()).toBe(true);
1393 expect(menu.shownItem(2).active()).toBe(false);
1394 expect(menu.shownItem(3)).toBe(undefined);
1395
1396 // Choose value 2
1397 expect(menu.show(2)).toBe(true);
1398
1399 expect(menu.shownItem(0).active()).toBe(false);
1400 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1401 expect(menu.shownItem(1).active()).toBe(false);
1402 expect(menu.shownItem(2).active()).toBe(true);
1403 expect(menu.shownItem(3)).toBe(undefined);
1404 });
1405
1406 it('should scroll to a chosen value (2)', function () {
1407 var menu = KorAP.OwnMenu.create(demolonglist);
1408
1409 // Choose value 3
1410 expect(menu.limit(3).show(3)).toBe(true);
1411 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1412 expect(menu.shownItem(0).active()).toBe(true);
1413 expect(menu.shownItem(1).active()).toBe(false);
1414 expect(menu.shownItem(2).active()).toBe(false);
1415 expect(menu.shownItem(3)).toBe(undefined);
1416 });
1417
1418 xit('should scroll to a chosen value after prefixing, if the chosen value is live');
1419 });
1420
1421 describe('KorAP.Prefix', function () {
1422 it('should be initializable', function () {
1423 var p = prefixClass.create();
1424 expect(p.element().classList.contains('pref')).toBeTruthy();
1425 expect(p.isSet()).not.toBeTruthy();
1426
1427 /*
1428 expect(mi.lcField()).toEqual(' baum');
1429 */
1430
1431 });
1432
1433 it('should be modifiable', function () {
1434 var p = prefixClass.create();
1435 expect(p.value()).toEqual('');
1436 expect(p.element().firstChild).toBeNull();
1437
1438 // Set string
1439 expect(p.value('Test')).toEqual('Test');
1440 expect(p.value()).toEqual('Test');
1441 expect(p.element().firstChild.nodeValue).toEqual('Test');
1442
1443 // Add string
1444 expect(p.add('ified')).toEqual('Testified');
1445 expect(p.value()).toEqual('Testified');
1446 expect(p.element().firstChild.nodeValue).toEqual('Testified');
1447
1448 // Clear string
1449 p.clear();
1450 expect(p.value()).toEqual('');
1451 expect(p.element().firstChild).toBeNull();
1452
1453 // Set string
1454 expect(p.value('Test')).toEqual('Test');
1455 expect(p.value()).toEqual('Test');
1456 expect(p.element().firstChild.nodeValue).toEqual('Test');
1457
1458 expect(p.chop()).toEqual('Tes');
1459 expect(p.value()).toEqual('Tes');
1460 expect(p.element().firstChild.nodeValue).toEqual('Tes');
1461
1462 expect(p.chop()).toEqual('Te');
1463 expect(p.value()).toEqual('Te');
1464 expect(p.element().firstChild.nodeValue).toEqual('Te');
1465
1466 expect(p.chop()).toEqual('T');
1467 expect(p.value()).toEqual('T');
1468 expect(p.element().firstChild.nodeValue).toEqual('T');
1469
1470 expect(p.chop()).toEqual('');
1471 expect(p.value()).toEqual('');
1472 expect(p.element().firstChild).toBeNull();
1473 });
1474
1475 it('should be activatable', function () {
1476 var p = prefixClass.create();
1477 expect(p.value()).toEqual('');
1478 expect(p.element().firstChild).toBeNull();
1479
1480 expect(p.value('Test')).toEqual('Test');
1481 expect(p.element().firstChild.nodeValue).toEqual('Test');
1482
1483 expect(p.active()).not.toBeTruthy();
1484 expect(p.element().classList.contains('active')).not.toBeTruthy();
1485
1486 p.active(true);
1487 expect(p.active()).toBeTruthy();
1488 expect(p.element().classList.contains('active')).toBeTruthy();
1489 });
1490 });
1491
1492 describe('KorAP.LengthField', function () {
1493 it('should be initializable', function () {
1494 var l = lengthFieldClass.create();
1495 expect(l.element().classList.contains('lengthField')).toBeTruthy();
1496 expect(l.element().children.length).toEqual(0);
1497 });
1498
1499 it('should be extensible', function () {
1500 var l = lengthFieldClass.create();
1501 l.add(['Baum']);
1502 expect(l.element().children.length).toEqual(1);
1503 expect(l.element().children[0].nodeName).toEqual('SPAN');
1504 expect(l.element().children[0].textContent).toEqual('Baum--');
1505 l.add(['Fragezeichen']);
1506 expect(l.element().children.length).toEqual(2);
1507 expect(l.element().children[1].nodeName).toEqual('SPAN');
1508 expect(l.element().children[1].textContent).toEqual('Fragezeichen--');
1509 });
1510
1511 it('should be correctly initializable', function () {
1512 var list = [
1513 ["Constituency"],
1514 ["Lemma"],
1515 ["Morphology"],
1516 ["Part-of-Speech"],
1517 ["Syntax"]
1518 ];
1519
1520 var menu = KorAP.OwnMenu.create(list);
1521
1522 expect(menu.lengthField().element().children.length).toEqual(5);
1523 });
1524 });
1525
1526 describe('KorAP.Slider', function () {
1527
1528 var demolonglist = [
1529 ['Titel', 'title'],
1530 ['Untertitel', 'subTitle'],
1531 ['Veröffentlichungsdatum', 'pubDate'],
1532 ['Länge', 'length'],
1533 ['Autor', 'author'],
1534 ['Genre', 'genre'],
1535 ['corpusID', 'corpusID'],
1536 ['docID', 'docID'],
1537 ['textID', 'textID'],
1538 ];
1539
1540 it('should correctly be initializable', function () {
1541 var list = [
1542 ["Constituency"],
1543 ["Lemma"],
1544 ["Morphology"],
1545 ["Part-of-Speech"],
1546 ["Syntax"]
1547 ];
1548
1549 var menu = KorAP.OwnMenu.create(list);
1550
1551 menu._firstActive = true;
1552 menu.limit(3);
1553
1554 expect(menu.show()).toBe(true);
1555
1556 expect(menu.shownItem(0).active()).toBe(true);
1557 expect(menu.shownItem(1).active()).toBe(false);
1558 expect(menu.shownItem(2).active()).toBe(false);
1559 expect(menu.slider().offset()).toEqual(0);
1560 expect(menu.position).toEqual(0);
1561 });
1562
1563 it('should correctly move on arrow keys', function () {
1564 var list = [
1565 ["Constituency"],
1566 ["Lemma"],
1567 ["Morphology"],
1568 ["Part-of-Speech"],
1569 ["Syntax"]
1570 ];
1571
1572 var menu = KorAP.OwnMenu.create(list);
1573
1574 menu._firstActive = true;
1575 menu.limit(3);
1576
1577 expect(menu.show()).toBe(true);
1578
1579 menu.next();
1580 expect(menu.shownItem(0).active()).toBe(false);
1581 expect(menu.shownItem(1).active()).toBe(true);
1582 expect(menu.shownItem(2).active()).toBe(false);
1583 expect(menu.slider().offset()).toEqual(0);
1584 expect(menu.position).toEqual(1);
1585
1586 menu.next();
1587 expect(menu.shownItem(0).active()).toBe(false);
1588 expect(menu.shownItem(1).active()).toBe(false);
1589 expect(menu.shownItem(2).active()).toBe(true);
1590 expect(menu.slider().offset()).toEqual(0);
1591 expect(menu.position).toEqual(2);
1592
1593 menu.next();
1594 expect(menu.shownItem(0).active()).toBe(false);
1595 expect(menu.shownItem(1).active()).toBe(false);
1596 expect(menu.shownItem(2).active()).toBe(true);
1597 expect(menu.slider().offset()).toEqual(1);
1598 expect(menu.position).toEqual(3);
1599
1600 menu.next();
1601 expect(menu.shownItem(0).active()).toBe(false);
1602 expect(menu.shownItem(1).active()).toBe(false);
1603 expect(menu.shownItem(2).active()).toBe(true);
1604 expect(menu.slider().offset()).toEqual(2);
1605 expect(menu.position).toEqual(4);
1606
1607 menu.next();
1608 expect(menu.shownItem(0).active()).toBe(true);
1609 expect(menu.shownItem(1).active()).toBe(false);
1610 expect(menu.shownItem(2).active()).toBe(false);
1611 expect(menu.slider().offset()).toEqual(0);
1612 expect(menu.position).toEqual(0);
1613
1614 expect(menu.slider()._slider.style.height).toEqual('60%');
1615 });
1616
1617 it('should correctly resize on prefixing', function () {
1618 var menu = KorAP.OwnMenu.create(demolonglist);
1619 menu._firstActive = true;
1620 menu.limit(3);
1621
1622 expect(menu.show()).toBe(true);
1623 expect(menu.slider().offset()).toEqual(0);
1624 expect(menu.slider().length()).toEqual(9);
1625
1626 expect(menu.prefix("e").show()).toBe(true);
1627 expect(menu.slider().length()).toEqual(6);
1628
1629 expect(menu.prefix("el").show()).toBe(true);
1630 expect(menu.slider().length()).toEqual(2);
1631
1632 expect(menu.prefix("e").show()).toBe(true);
1633 expect(menu.slider().length()).toEqual(6);
1634
1635 expect(menu.prefix("").show()).toBe(true);
1636 expect(menu.slider().length()).toEqual(9);
1637 });
1638
1639
1640 it('should correctly move the list on mousemove', function () {
1641 var list = [
1642 ["Constituency"],
1643 ["Lemma"],
1644 ["Morphology"],
1645 ["Part-of-Speech"],
1646 ["Syntax"]
1647 ];
1648
1649 var menu = KorAP.OwnMenu.create(list);
1650
1651 menu._firstActive = true;
1652 menu.limit(3);
1653
1654 expect(menu.show()).toBe(true);
1655
1656 expect(menu.shownItem(0).active()).toBe(true);
1657 expect(menu.shownItem(1).active()).toBe(false);
1658 expect(menu.shownItem(2).active()).toBe(false);
1659 expect(menu.slider().offset()).toEqual(0);
1660
1661 // This will normally be done on
1662 menu.slider()._rulerHeight = 100;
1663 menu.slider()._sliderHeight = 40;
1664 menu.slider()._event.initOffset = 0;
1665 expect(menu.slider().length()).toEqual(5);
1666
1667 menu.slider().movetoRel(10);
1668 expect(menu.slider().offset()).toEqual(0);
1669
1670 expect(menu.shownItem(0).active()).toBe(true);
1671 expect(menu.shownItem(0).lcField()).toEqual(' constituency');
1672 menu.slider().movetoRel(24);
1673 expect(menu.slider().offset()).toEqual(0);
1674 menu.slider().movetoRel(25);
1675 expect(menu.slider().offset()).toEqual(0);
1676
1677 menu.slider().movetoRel(30);
1678 expect(menu.slider().offset()).toEqual(1);
1679 menu.slider().movetoRel(59);
1680 expect(menu.slider().offset()).toEqual(1);
1681 expect(menu.shownItem(0).active()).toBe(false);
1682 expect(menu.shownItem(0).lcField()).toEqual(' lemma');
1683
1684 // Everything > 60 is offset 2
1685 menu.slider().movetoRel(60);
1686 expect(menu.slider().offset()).toEqual(2);
1687 menu.slider().movetoRel(180);
1688 expect(menu.slider().offset()).toEqual(2);
1689 expect(menu.shownItem(0).active()).toBe(false);
1690 expect(menu.shownItem(0).lcField()).toEqual(' morphology');
1691
1692 expect(menu.shownItem(1).active()).toBe(false);
1693 expect(menu.shownItem(2).active()).toBe(false);
1694
1695 // When the active cursor moves again - scroll to viewport
1696 // cursor is before viewport
1697 menu.next();
1698 expect(menu.shownItem(0).active()).toBe(true);
1699 expect(menu.shownItem(0).lcField()).toEqual(' lemma');
1700 expect(menu.shownItem(1).active()).toBe(false);
1701 expect(menu.shownItem(2).active()).toBe(false);
1702
1703 menu.next();
1704 menu.next();
1705 expect(menu.shownItem(0).active()).toBe(false);
1706 expect(menu.shownItem(0).lcField()).toEqual(' lemma');
1707 expect(menu.shownItem(1).active()).toBe(false);
1708 expect(menu.shownItem(1).lcField()).toEqual(' morphology');
1709 expect(menu.shownItem(2).active()).toBe(true);
1710 expect(menu.shownItem(2).lcField()).toEqual(' part-of-speech');
1711
1712 menu.slider().movetoRel(0);
1713 expect(menu.slider().offset()).toEqual(0);
1714 expect(menu.shownItem(0).active()).toBe(false);
1715 expect(menu.shownItem(0).lcField()).toEqual(' constituency');
1716 expect(menu.shownItem(1).active()).toBe(false);
1717 expect(menu.shownItem(1).lcField()).toEqual(' lemma');
1718 expect(menu.shownItem(2).active()).toBe(false);
1719 expect(menu.shownItem(2).lcField()).toEqual(' morphology');
1720
1721 // cursor is after viewport
1722 menu.next();
1723 expect(menu.slider().offset()).toEqual(2);
1724 expect(menu.shownItem(0).active()).toBe(false);
1725 expect(menu.shownItem(0).lcField()).toEqual(' morphology');
1726 expect(menu.shownItem(1).active()).toBe(false);
1727 expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech');
1728 expect(menu.shownItem(2).active()).toBe(true);
1729 expect(menu.shownItem(2).lcField()).toEqual(' syntax');
1730
1731 menu.slider().movetoRel(0);
1732 expect(menu.slider().offset()).toEqual(0);
1733 expect(menu.shownItem(0).active()).toBe(false);
1734 expect(menu.shownItem(0).lcField()).toEqual(' constituency');
1735 expect(menu.shownItem(1).active()).toBe(false);
1736 expect(menu.shownItem(1).lcField()).toEqual(' lemma');
1737 expect(menu.shownItem(2).active()).toBe(false);
1738 expect(menu.shownItem(2).lcField()).toEqual(' morphology');
1739
1740 menu.prev();
1741 expect(menu.slider().offset()).toEqual(2);
1742 expect(menu.shownItem(0).lcField()).toEqual(' morphology');
1743 expect(menu.shownItem(0).active()).toBe(false);
1744 expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech');
1745 expect(menu.shownItem(1).active()).toBe(true);
1746 expect(menu.shownItem(2).lcField()).toEqual(' syntax');
1747 expect(menu.shownItem(2).active()).toBe(false);
1748
1749 menu.prev();
1750 menu.prev();
1751 expect(menu.slider().offset()).toEqual(1);
1752 expect(menu.shownItem(0).lcField()).toEqual(' lemma');
1753 expect(menu.shownItem(0).active()).toBe(true);
1754 expect(menu.shownItem(1).lcField()).toEqual(' morphology');
1755 expect(menu.shownItem(1).active()).toBe(false);
1756 expect(menu.shownItem(2).lcField()).toEqual(' part-of-speech');
1757 expect(menu.shownItem(2).active()).toBe(false);
1758
1759 menu.slider().movetoRel(100);
1760 expect(menu.slider().offset()).toEqual(2);
1761 expect(menu.shownItem(0).lcField()).toEqual(' morphology');
1762 expect(menu.shownItem(0).active()).toBe(false);
1763 expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech');
1764 expect(menu.shownItem(1).active()).toBe(false);
1765 expect(menu.shownItem(2).lcField()).toEqual(' syntax');
1766 expect(menu.shownItem(2).active()).toBe(false);
1767
1768 menu.prev();
1769 expect(menu.slider().offset()).toEqual(0);
1770 expect(menu.shownItem(0).lcField()).toEqual(' constituency');
1771 expect(menu.shownItem(0).active()).toBe(true);
1772 expect(menu.shownItem(1).lcField()).toEqual(' lemma');
1773 expect(menu.shownItem(1).active()).toBe(false);
1774 expect(menu.shownItem(2).lcField()).toEqual(' morphology');
1775 expect(menu.shownItem(2).active()).toBe(false);
1776 });
1777 });
1778
1779 describe('KorAP.MenuBenchmark', function () {
1780 var menu = menuClass.create([
1781 ['Titel', 'title'],
1782 ['Untertitel', 'subTitle'],
1783 ['Veröffentlichungsdatum', 'pubDate'],
1784 ['Länge', 'length'],
1785 ['Autor', 'author']
1786 ]);
1787
1788 menu.limit(3).show();
1789
1790 // Some actions
1791 menu.next();
1792 menu.next();
1793 menu.prev();
1794 menu.prev();
1795 menu.prev();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001796
Akron3c2730f2016-05-24 15:08:29 +02001797 menu.pageDown();
Akron3c2730f2016-05-24 15:08:29 +02001798 menu.pageUp();
1799
Akronaba7a5a2016-08-15 21:58:33 +02001800 // There is no fourth item in the list!
1801 menu.prefix('e').show(4);
Akron5a1f5bb2016-05-23 22:00:39 +02001802 menu.next();
1803 menu.next();
Akron5a1f5bb2016-05-23 22:00:39 +02001804 menu.prev();
1805 menu.prev();
Akron5a1f5bb2016-05-23 22:00:39 +02001806 menu.prev();
Akronf86eaea2016-05-13 18:02:27 +02001807 });
1808 });