blob: aba3f1e2973bfcf721125b5f1db53088d4e7f0dc [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");
298 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>");
299
300 menuItem.lowlight();
301 expect(menuItem.element().innerHTML).toEqual(plain);
302
303 // Highlight in the end - second
304 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
305 menuItem.highlight("le");
306 expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Examp<mark>le</mark></h3></div>");
307
308 menuItem.lowlight();
309 expect(menuItem.element().innerHTML).toEqual(plain);
310
311 // Highlight at the beginning - second
312 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
313 menuItem.highlight("this");
314 expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3><mark>This</mark> is my Example</h3></div>");
315
316 menuItem.lowlight();
317 expect(menuItem.element().innerHTML).toEqual(plain);
318 });
319 });
320
321
322 describe('KorAP.Menu', function () {
323 var list = [
324 ["Constituency", "c=", "Example 1"],
325 ["Lemma", "l="],
326 ["Morphology", "m=", "Example 2"],
327 ["Part-of-Speech", "p="],
328 ["Syntax", "syn="]
329 ];
330
331 var demolist = [
332 ['Titel', 'title'],
333 ['Untertitel', 'subTitle'],
334 ['Veröffentlichungsdatum', 'pubDate'],
335 ['Länge', 'length'],
336 ['Autor', 'author']
337 ];
338
339 var demolonglist = [
340 ['Titel', 'title'],
341 ['Untertitel', 'subTitle'],
342 ['Veröffentlichungsdatum', 'pubDate'],
343 ['Länge', 'length'],
344 ['Autor', 'author'],
345 ['Genre', 'genre'],
346 ['corpusID', 'corpusID'],
347 ['docID', 'docID'],
348 ['textID', 'textID'],
349 ];
350
351 it('should be initializable', function () {
352 var list = [
353 ["Constituency"],
354 ["Lemma"],
355 ["Morphology"],
356 ["Part-of-Speech"],
357 ["Syntax"]
358 ];
359
360 var menu = KorAP.OwnMenu.create(list);
361 menu._firstActive = true;
362 expect(menu.itemClass()).toEqual(KorAP.OwnMenuItem);
363 expect(menu.element().nodeName).toEqual('UL');
364 expect(menu.element().classList.contains('visible')).toBeFalsy();
365 expect(menu.limit()).toEqual(8);
366
367 menu.limit(9);
368 expect(menu.limit()).toEqual(9);
369
370 menu.limit(8);
371
372 // view
373 menu.show();
374
375 // First element in list
376 expect(menu.item(0).active()).toBe(true);
377 expect(menu.item(0).noMore()).toBe(true);
378
379 // Middle element in list
380 expect(menu.item(2).active()).toBe(false);
381 expect(menu.item(2).noMore()).toBe(false);
382
383 // Last element in list
384 expect(menu.item(menu.length() - 1).active()).toBe(false);
385 expect(menu.item(menu.length() - 1).noMore()).toBe(true);
386 });
387
388 it('should have a reference to the menu', function () {
389 var menu = KorAP.HintMenu.create("cnx/", list);
390 expect(menu.item(0).menu()).toEqual(menu);
391
392 menu = KorAP.HintMenu.create("cnx/", list);
393 expect(menu.element().menu).toEqual(menu);
394 });
395
396
397 it('should be visible', function () {
398 var menu = KorAP.HintMenu.create("cnx/", list);
399 expect(menu.removeItems()).toBe(undefined);
400 menu.limit(3);
401
402 expect(menu.show()).toBe(true);
403
404 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
405 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>");
406 expect(menu.element().childNodes[4].getAttribute("data-action")).toEqual("l=");
407 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
408 expect(menu.element().childNodes[6]).toBe(undefined);
409
410 // Check boundaries
411 expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(true);
412 expect(menu.element().childNodes[4].classList.contains("no-more")).toBe(false);
413 expect(menu.element().childNodes[5].classList.contains("no-more")).toBe(false);
414 });
415
416 it('should be filterable', function () {
417 var menu = KorAP.HintMenu.create("cnx/", list);
418 menu.limit(3);
419 expect(menu.prefix("o").show()).toBe(true);
420 expect(menu.element().childNodes[0].innerHTML).toEqual("o");
421 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
422 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>");
423 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
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(true);
430
431 menu.limit(2);
432
433 expect(menu.prefix("o").show()).toBe(true);
434 expect(menu.element().childNodes[0].innerHTML).toEqual("o");
435 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
436 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>");
437 expect(menu.element().childNodes[5]).toBe(undefined);
438
439 // Check boundaries
440 expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(true);
441 expect(menu.element().childNodes[4].classList.contains("no-more")).toBe(false);
442 expect(menu.element().childNodes[5]).toBe(undefined);
443
444 expect(menu.prefix("e").show()).toBe(true);
445 expect(menu.element().childNodes[0].innerHTML).toEqual("e");
446 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
447 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
448 expect(menu.element().childNodes[5]).toBe(undefined);
449
450 menu.limit(5);
451 expect(menu.prefix("a").show()).toBe(true);
452 expect(menu.element().childNodes[0].innerHTML).toEqual("a");
453 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Ex<mark>a</mark>mple 1</span>");
454 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemm<mark>a</mark></strong>");
455 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Ex<mark>a</mark>mple 2</span>");
456 expect(menu.element().childNodes[6].innerHTML).toEqual("<strong>P<mark>a</mark>rt-of-Speech</strong>");
457 expect(menu.element().childNodes[7].innerHTML).toEqual("<strong>Synt<mark>a</mark>x</strong>");
458 expect(menu.element().childNodes[8]).toBe(undefined);
459 });
460
461
462 it('should be nextable', function () {
463 var menu = KorAP.HintMenu.create("cnx/", list);
464 menu._firstActive = true;
465
466 // Show only 3 items
467 menu.limit(3);
468 expect(menu.show()).toBe(true);
469 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
470 expect(menu.shownItem(0).active()).toBe(true);
471 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>");
472 expect(menu.shownItem(1).active()).toBe(false);
473 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
474 expect(menu.shownItem(2).active()).toBe(false);
475 expect(menu.element().childNodes[6]).toBe(undefined);
476
477 // Activate next (1)
478 menu.next();
479 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
480 expect(menu.shownItem(0).active()).toBe(false);
481 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>");
482 expect(menu.shownItem(1).active()).toBe(true);
483 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
484 expect(menu.shownItem(2).active()).toBe(false);
485 expect(menu.element().childNodes[6]).toBe(undefined);
486
487 // Activate next (2)
488 menu.next();
489 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
490 expect(menu.shownItem(0).active()).toBe(false);
491 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>");
492 expect(menu.shownItem(1).active()).toBe(false);
493 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
494 expect(menu.shownItem(2).active()).toBe(true);
495 expect(menu.element().childNodes[6]).toBe(undefined);
496
497 // Activate next (3)
498 // scroll!
499 menu.next();
500 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Lemma</strong>");
501 expect(menu.shownItem(0).active()).toBe(false);
502 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
503 expect(menu.shownItem(1).active()).toBe(false);
504 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
505 expect(menu.shownItem(2).active()).toBe(true);
506 expect(menu.element().childNodes[6]).toBe(undefined);
507
508 // Activate next (4)
509 menu.next();
510 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
511 expect(menu.shownItem(0).active()).toBe(false);
512 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
513 expect(menu.shownItem(1).active()).toBe(false);
514 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Syntax</strong>");
515 expect(menu.shownItem(2).active()).toBe(true);
516 expect(menu.element().childNodes[6]).toBe(undefined);
517
518 // Activate next (5) - ROLL
519 menu.next();
520 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
521 expect(menu.shownItem(0).active()).toBe(true);
522 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>");
523 expect(menu.shownItem(1).active()).toBe(false);
524 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
525 expect(menu.shownItem(2).active()).toBe(false);
526 expect(menu.element().childNodes[6]).toBe(undefined);
527
528 // Active next (6)
529 menu.next();
530 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
531 expect(menu.shownItem(0).active()).toBe(false);
532 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>");
533 expect(menu.shownItem(1).active()).toBe(true);
534 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
535 expect(menu.shownItem(2).active()).toBe(false);
536 expect(menu.element().childNodes[6]).toBe(undefined);
537 });
538
539 it('should be nextable without active field', function () {
540 var menu = KorAP.HintMenu.create("cnx/", list);
541 menu.limit(3);
542 expect(menu.show()).toBe(true);
543 menu.next();
544 expect(menu.shownItem(0).active()).toEqual(true);
545 });
546
547
548 it('should be prevable', function () {
549 var menu = KorAP.HintMenu.create("cnx/", list);
550 menu._firstActive = true;
551 menu.limit(3);
552 expect(menu.show()).toBe(true);
553
554 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
555 expect(menu.shownItem(0).active()).toBe(true);
556 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>");
557 expect(menu.shownItem(1).active()).toBe(false);
558 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
559 expect(menu.shownItem(2).active()).toBe(false);
560 expect(menu.element().childNodes[6]).toBe(undefined);
561
562 // Activate prev (1) - roll to bottom
563 menu.prev();
564 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
565 expect(menu.shownItem(0).active()).toBe(false);
566 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
567 expect(menu.shownItem(1).active()).toBe(false);
568 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Syntax</strong>");
569 expect(menu.shownItem(2).active()).toBe(true);
570 expect(menu.element().childNodes[6]).toBe(undefined);
571
572 // Activate prev (2)
573 menu.prev();
574 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
575 expect(menu.shownItem(0).active()).toBe(false);
576 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
577 expect(menu.shownItem(1).active()).toBe(true);
578 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Syntax</strong>");
579 expect(menu.shownItem(2).active()).toBe(false);
580 expect(menu.element().childNodes[6]).toBe(undefined);
581
582 // Activate prev (3)
583 menu.prev();
584 expect(menu.shownItem(0).name()).toEqual("Morphology");
585 expect(menu.shownItem(0).active()).toBe(true);
586 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
587 expect(menu.shownItem(1).active()).toBe(false);
588 expect(menu.shownItem(2).name()).toEqual("Syntax");
589 expect(menu.shownItem(2).active()).toBe(false);
590 expect(menu.element().childNodes[6]).toBe(undefined);
591
592 // Activate prev (4)
593 menu.prev();
594 expect(menu.shownItem(0).name()).toEqual("Lemma");
595 expect(menu.shownItem(0).active()).toBe(true);
596 expect(menu.shownItem(1).name()).toEqual("Morphology");
597 expect(menu.shownItem(1).active()).toBe(false);
598 expect(menu.shownItem(2).name()).toEqual("Part-of-Speech");
599 expect(menu.shownItem(2).active()).toBe(false);
600 expect(menu.element().childNodes[6]).toBe(undefined);
601
602 // Activate prev (5)
603 menu.prev();
604 expect(menu.shownItem(0).name()).toEqual("Constituency");
605 expect(menu.shownItem(0).active()).toBe(true);
606 expect(menu.shownItem(1).name()).toEqual("Lemma");
607 expect(menu.shownItem(1).active()).toBe(false);
608 expect(menu.shownItem(2).name()).toEqual("Morphology");
609 expect(menu.shownItem(2).active()).toBe(false);
610 expect(menu.element().childNodes[6]).toBe(undefined);
611
612 // Activate next (1)
613 menu.next();
614 expect(menu.shownItem(0).name()).toEqual("Constituency");
615 expect(menu.shownItem(0).active()).toBe(false);
616 expect(menu.shownItem(1).name()).toEqual("Lemma");
617 expect(menu.shownItem(1).active()).toBe(true);
618 expect(menu.shownItem(2).name()).toEqual("Morphology");
619 expect(menu.shownItem(2).active()).toBe(false);
620 expect(menu.element().childNodes[6]).toBe(undefined);
621
622 // Activate prev (6)
623 menu.prev();
624
625 // Activate prev (7)
626 menu.prev();
627 expect(menu.shownItem(0).name()).toEqual("Morphology");
628 expect(menu.shownItem(0).active()).toBe(false);
629 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
630 expect(menu.shownItem(1).active()).toBe(false);
631 expect(menu.shownItem(2).name()).toEqual("Syntax");
632 expect(menu.shownItem(2).active()).toBe(true);
633 expect(menu.element().childNodes[6]).toBe(undefined);
634 });
635
636 it('should be prevable without active field', function () {
637 var menu = KorAP.HintMenu.create("cnx/", list);
638 menu.limit(3);
639 expect(menu.show()).toBe(true);
640 menu.prev();
641 expect(menu.shownItem(2).active()).toEqual(true);
642 expect(menu.shownItem(2).lcField()).toEqual(' syntax');
643 });
644
645 it('should be navigatable and filterable (prefix = "o")', function () {
646 var menu = KorAP.HintMenu.create("cnx/", list);
647 menu._firstActive = true;
648 menu.limit(2);
649
650 expect(menu.prefix("o").show()).toBe(true);
651 expect(menu.shownItem(0).name()).toEqual("Constituency");
652 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
653 expect(menu.shownItem(0).active()).toBe(true);
654 expect(menu.shownItem(1).name()).toEqual("Morphology");
655 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>");
656 expect(menu.shownItem(1).active()).toBe(false);
657 expect(menu.shownItem(2)).toBe(undefined);
658
659 // Next (1)
660 menu.next();
661 expect(menu.shownItem(0).name()).toEqual("Constituency");
662 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
663 expect(menu.shownItem(0).active()).toBe(false);
664 expect(menu.shownItem(1).name()).toEqual("Morphology");
665 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>");
666 expect(menu.shownItem(1).active()).toBe(true);
667 expect(menu.shownItem(2)).toBe(undefined);
668
669 // Next (2)
670 menu.next();
671 expect(menu.shownItem(0).name()).toEqual("Morphology");
672 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>");
673 expect(menu.shownItem(0).active()).toBe(false);
674 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
675 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
676 expect(menu.shownItem(1).active()).toBe(true);
677 expect(menu.shownItem(2)).toBe(undefined);
678
679 // Next (3) - to prefix
680 menu.next();
681 expect(menu.shownItem(0).name()).toEqual("Morphology");
682 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>");
683 expect(menu.shownItem(0).active()).toBe(false);
684 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
685 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
686 expect(menu.shownItem(1).active()).toBe(false);
687 expect(menu.shownItem(2)).toBe(undefined);
688
689 menu.next();
690 expect(menu.shownItem(0).name()).toEqual("Constituency");
691 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
692 expect(menu.shownItem(0).active()).toBe(true);
693 expect(menu.shownItem(1).name()).toEqual("Morphology");
694 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>");
695 expect(menu.shownItem(1).active()).toBe(false);
696 expect(menu.shownItem(2)).toBe(undefined);
697 });
698
699
700 it('should be navigatable and filterable (prefix = "ex", "e")', function () {
701 var menu = KorAP.HintMenu.create("cnx/", list);
702 menu._firstActive = true;
703
704 menu.limit(2);
705 expect(menu.prefix("ex").show()).toBe(true);
706
707 expect(menu.shownItem(0).name()).toEqual("Constituency");
708 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
709 expect(menu.shownItem(0).active()).toBe(true);
710 expect(menu.shownItem(1).name()).toEqual("Morphology");
711 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
712 expect(menu.shownItem(1).active()).toBe(false);
713 expect(menu.shownItem(2)).toBe(undefined);
714
715 // Next (1)
716 menu.next();
717 expect(menu.shownItem(0).name()).toEqual("Constituency");
718 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
719 expect(menu.shownItem(0).active()).toBe(false);
720 expect(menu.shownItem(1).name()).toEqual("Morphology");
721 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
722 expect(menu.shownItem(1).active()).toBe(true);
723 expect(menu.shownItem(2)).toBe(undefined);
724
725 // Next (2)
726 menu.next();
727
728 expect(menu.prefix()).toEqual('ex');
729 expect(menu.shownItem(0).name()).toEqual("Constituency");
730 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
731 expect(menu.shownItem(0).active()).toBe(false);
732
733 expect(menu.shownItem(1).name()).toEqual("Morphology");
734 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
735 expect(menu.shownItem(1).active()).toBe(false);
736 expect(menu.shownItem(2)).toBe(undefined);
737
738 // Reset limit
739 menu.limit(5);
740
741 // Change show
742 expect(menu.prefix("e").show()).toBe(true);
743 expect(menu._prefix.active()).toBe(false);
744 expect(menu.shownItem(0).name()).toEqual("Constituency");
745 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
746 expect(menu.shownItem(0).active()).toBe(true);
747 expect(menu.shownItem(1).name()).toEqual("Morphology");
748 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
749 expect(menu.shownItem(1).active()).toBe(false);
750 expect(menu.shownItem(2)).toBe(undefined);
751
752 // Next (1)
753 menu.next();
754 expect(menu._prefix.active()).toBe(false);
755 expect(menu.prefix()).toEqual('e');
756 expect(menu.shownItem(0).name()).toEqual("Constituency");
757 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
758 expect(menu.shownItem(0).active()).toBe(false);
759 expect(menu.shownItem(1).name()).toEqual("Morphology");
760 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
761 expect(menu.shownItem(1).active()).toBe(true);
762 expect(menu.shownItem(2)).toBe(undefined);
763
764 // Next (2)
765 menu.next();
766 expect(menu._prefix.active()).toBe(true);
767 expect(menu.shownItem(0).name()).toEqual("Constituency");
768 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
769 expect(menu.shownItem(0).active()).toBe(false);
770 expect(menu.shownItem(1).name()).toEqual("Morphology");
771 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
772 expect(menu.shownItem(1).active()).toBe(false);
773 expect(menu.shownItem(2)).toBe(undefined);
774
775 // Next (3)
776 menu.next();
777 expect(menu._prefix.active()).toBe(false);
778 expect(menu.shownItem(0).name()).toEqual("Constituency");
779 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
780 expect(menu.shownItem(0).active()).toBe(true);
781 expect(menu.shownItem(1).name()).toEqual("Morphology");
782 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
783 expect(menu.shownItem(1).active()).toBe(false);
784 expect(menu.shownItem(2)).toBe(undefined);
785 });
786
787
788 it('should choose prefix with failing prefix (1)', function () {
789 var menu = KorAP.HintMenu.create("cnx/", list);
790 menu.limit(2);
791 expect(menu.prefix("exit").show()).toBe(true);
792 expect(menu.element().querySelector('li')).toBe(null);
793 expect(menu.shownItem(0)).toBeUndefined();
794 expect(menu._prefix.active()).toBe(true);
795 });
796
797
798 it('should choose prefix with failing prefix (2)', function () {
799 var menu = KorAP.HintMenu.create("cnx/", list);
800 menu.limit(2);
801 expect(menu.show()).toBe(true);
802 expect(menu.prefix("exit").show()).toBe(true);
803 expect(menu.element().querySelector('li')).toBe(null);
804 expect(menu.shownItem(0)).toBeUndefined();
805 expect(menu._prefix.active()).toBe(true);
806 });
807
808 it('should ignore navigation with failing prefix', function () {
809 var menu = KorAP.HintMenu.create("cnx/", list);
810 menu.limit(2);
811 expect(menu.show()).toBe(true);
812
813 menu.next();
814
815 expect(menu.prefix("exit").show()).toBe(true);
816 expect(menu.element().querySelector('li')).toBe(null);
817 expect(menu.shownItem(0)).toBeUndefined();
818 expect(menu._prefix.active()).toBe(true);
819
820 menu.next();
821 expect(menu._prefix.active()).toBe(true);
822
823 menu.prev();
824 expect(menu._prefix.active()).toBe(true);
825
826 });
827
828 it('should be navigatable with prefix', function () {
829 var menu = KorAP.HintMenu.create("cnx/", demolist);
830 menu._firstActive = true;
831
832 menu.limit(3);
833
834 expect(menu.show()).toBe(true);
835 expect(menu.prefix()).toEqual("");
836
837 expect(menu.shownItem(0).name()).toEqual("Titel");
838 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
839 expect(menu.shownItem(0).active()).toBe(true);
840 expect(menu.shownItem(1).name()).toEqual("Untertitel");
841 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
842 expect(menu.shownItem(1).active()).toBe(false);
843 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
844 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
845 expect(menu.shownItem(2).active()).toBe(false);
846 expect(menu.shownItem(3)).toBe(undefined);
847
848 menu._prefix.add('a');
849 expect(menu.show()).toBe(true);
850 expect(menu.prefix()).toEqual("a");
851 expect(menu.shownItem(0).name()).toEqual("Autor");
852 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
853
854 menu._prefix.add('u');
855 expect(menu.show()).toBe(true);
856 expect(menu.prefix()).toEqual("au");
857 expect(menu.shownItem(0).name()).toEqual("Autor");
858 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong><mark>Au</mark>tor</strong>");
859
860 menu._prefix.chop();
861 expect(menu.show()).toBe(true);
862 expect(menu.prefix()).toEqual("a");
863 expect(menu.shownItem(0).name()).toEqual("Autor");
864 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
865
866 menu._prefix.chop();
867 expect(menu.show()).toBe(true);
868 expect(menu.prefix()).toEqual("");
869 expect(menu.shownItem(0).name()).toEqual("Titel");
870 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
871 expect(menu.shownItem(0).active()).toBe(true);
872 expect(menu.shownItem(1).name()).toEqual("Untertitel");
873 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
874 expect(menu.shownItem(1).active()).toBe(false);
875 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
876 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
877 expect(menu.shownItem(2).active()).toBe(false);
878 expect(menu.shownItem(3)).toBe(undefined);
879
880 // Forward
881 menu._prefix.chop();
882 expect(menu.show()).toBe(true);
883 expect(menu.prefix()).toEqual("");
884 expect(menu.shownItem(0).name()).toEqual("Titel");
885 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
886 expect(menu.shownItem(0).active()).toBe(true);
887 expect(menu.shownItem(1).name()).toEqual("Untertitel");
888 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
889 expect(menu.shownItem(1).active()).toBe(false);
890 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
891 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
892 expect(menu.shownItem(2).active()).toBe(false);
893
894 // Forward
895 menu.next();
896 expect(menu.prefix()).toEqual("");
897 expect(menu.shownItem(0).name()).toEqual("Titel");
898 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
899 expect(menu.shownItem(0).active()).toBe(false);
900 expect(menu.shownItem(1).name()).toEqual("Untertitel");
901 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
902 expect(menu.shownItem(1).active()).toBe(true);
903 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
904 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
905 expect(menu.shownItem(2).active()).toBe(false);
906 expect(menu.shownItem(3)).toBe(undefined);
907
908 // Forward
909 menu.next();
910 expect(menu.prefix()).toEqual("");
911 expect(menu.shownItem(0).name()).toEqual("Titel");
912 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
913 expect(menu.shownItem(0).active()).toBe(false);
914 expect(menu.shownItem(1).name()).toEqual("Untertitel");
915 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
916 expect(menu.shownItem(1).active()).toBe(false);
917 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
918 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
919 expect(menu.shownItem(2).active()).toBe(true);
920 expect(menu.shownItem(3)).toBe(undefined);
921
922 // Forward
923 menu.next();
924 expect(menu.prefix()).toEqual("");
925 expect(menu.shownItem(0).name()).toEqual("Untertitel");
926 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Untertitel</strong>");
927 expect(menu.shownItem(0).active()).toBe(false);
928 expect(menu.shownItem(1).name()).toEqual("Veröffentlichungsdatum");
929 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
930 expect(menu.shownItem(1).active()).toBe(false);
931 expect(menu.shownItem(2).name()).toEqual("Länge");
932 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Länge</strong>");
933 expect(menu.shownItem(2).active()).toBe(true);
934 expect(menu.shownItem(3)).toBe(undefined);
935
936 // Forward
937 menu.next();
938 expect(menu.prefix()).toEqual("");
939 expect(menu.shownItem(0).name()).toEqual("Veröffentlichungsdatum");
940 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
941 expect(menu.shownItem(0).active()).toBe(false);
942 expect(menu.shownItem(1).name()).toEqual("Länge");
943 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Länge</strong>");
944 expect(menu.shownItem(1).active()).toBe(false);
945 expect(menu.shownItem(2).name()).toEqual("Autor");
946 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Autor</strong>");
947 expect(menu.shownItem(2).active()).toBe(true);
948 expect(menu.shownItem(3)).toBe(undefined);
949
950 // Forward
951 menu.next();
952 expect(menu.prefix()).toEqual("");
953 expect(menu.shownItem(0).name()).toEqual("Titel");
954 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
955 expect(menu.shownItem(0).active()).toBe(true);
956 expect(menu.shownItem(1).name()).toEqual("Untertitel");
957 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
958 expect(menu.shownItem(1).active()).toBe(false);
959 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
960 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
961 expect(menu.shownItem(2).active()).toBe(false);
962 });
963
964
965 it('should be navigatable with a prefix (1)', function () {
966 var menu = KorAP.HintMenu.create("cnx/", demolist);
967 menu._firstActive = true;
968
969 menu.limit(3);
970
971 expect(menu.show()).toBe(true);
972 expect(menu.prefix()).toEqual("");
973
974 // Add prefix in uppercase - but check in lowercase
975 menu.prefix('El');
976 expect(menu.show()).toBe(true);
977
978 expect(menu.prefix()).toEqual("El");
979 expect(menu._prefix.active()).toEqual(false);
980 expect(menu.shownItem(0).name()).toEqual("Titel");
981 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
982 expect(menu.shownItem(0).active()).toBe(true);
983 expect(menu.shownItem(1).name()).toEqual("Untertitel");
984 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
985 expect(menu.shownItem(1).active()).toBe(false);
986 expect(menu.shownItem(2)).toBe(undefined);
987
988 // Forward
989 menu.next();
990 expect(menu.prefix()).toEqual("El");
991 expect(menu._prefix.active()).toEqual(false);
992 expect(menu.shownItem(0).name()).toEqual("Titel");
993 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
994 expect(menu.shownItem(0).active()).toBe(false);
995 expect(menu.shownItem(1).name()).toEqual("Untertitel");
996 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
997 expect(menu.shownItem(1).active()).toBe(true);
998 expect(menu.shownItem(2)).toBe(undefined);
999
1000 // Forward
1001 menu.next();
1002 expect(menu.prefix()).toEqual("El");
1003 expect(menu._prefix.active()).toEqual(true);
1004 expect(menu.shownItem(0).name()).toEqual("Titel");
1005 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1006 expect(menu.shownItem(0).active()).toBe(false);
1007 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1008 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1009 expect(menu.shownItem(1).active()).toBe(false);
1010 expect(menu.shownItem(2)).toBe(undefined);
1011
1012 // Backward
1013 menu.prev();
1014 expect(menu.prefix()).toEqual("El");
1015 expect(menu._prefix.active()).toEqual(false);
1016 expect(menu.shownItem(0).name()).toEqual("Titel");
1017 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1018 expect(menu.shownItem(0).active()).toBe(false);
1019
1020 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1021 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1022 expect(menu.shownItem(1).active()).toBe(true);
1023 expect(menu.shownItem(2)).toBe(undefined);
1024 });
1025
1026
1027 it('should be navigatable with a prefix (2)', function () {
1028 var menu = KorAP.HintMenu.create("cnx/", demolist);
1029 menu._firstActive = true;
1030
1031 menu.limit(3);
1032 expect(menu.show()).toBe(true);
1033 expect(menu.prefix()).toEqual("");
1034 menu.prefix('el');
1035 expect(menu.show()).toBe(true);
1036
1037 expect(menu.prefix()).toEqual("el");
1038 expect(menu._prefix.active()).toEqual(false);
1039 expect(menu.shownItem(0).name()).toEqual("Titel");
1040 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1041 expect(menu.shownItem(0).active()).toBe(true);
1042 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1043 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1044 expect(menu.shownItem(1).active()).toBe(false);
1045 expect(menu.shownItem(2)).toBe(undefined);
1046
1047 // Backward
1048 menu.prev();
1049 expect(menu._prefix.active()).toEqual(true);
1050
1051 expect(menu.shownItem(0).name()).toEqual("Titel");
1052 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1053 expect(menu.shownItem(0).active()).toBe(false);
1054
1055 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1056 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1057 expect(menu.shownItem(1).active()).toBe(false);
1058 expect(menu.shownItem(2)).toBe(undefined);
1059
1060 // Backward
1061 menu.prev();
1062 expect(menu._prefix.active()).toEqual(false);
1063 expect(menu.shownItem(0).name()).toEqual("Titel");
1064 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1065 expect(menu.shownItem(0).active()).toBe(false);
1066 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1067 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1068 expect(menu.shownItem(1).active()).toBe(true);
1069 expect(menu.shownItem(2)).toBe(undefined);
1070 });
1071
1072 it('should be navigatable with a prefix (3)', function () {
1073 var menu = KorAP.HintMenu.create("cnx/", demolist);
1074 menu._firstActive = true;
1075 menu.limit(3);
1076 expect(menu.show()).toBe(true);
1077 expect(menu.prefix()).toEqual("");
1078 menu.prefix('el');
1079 expect(menu.show()).toBe(true);
1080
1081 expect(menu.prefix()).toEqual("el");
1082 expect(menu._prefix.active()).toEqual(false);
1083 expect(menu.shownItem(0).name()).toEqual("Titel");
1084 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1085 expect(menu.shownItem(0).active()).toBe(true);
1086 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1087 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1088 expect(menu.shownItem(1).active()).toBe(false);
1089 expect(menu.shownItem(2)).toBe(undefined);
1090
1091 // Backward
1092 menu.prev();
1093 expect(menu._prefix.active()).toEqual(true);
1094 expect(menu.shownItem(0).name()).toEqual("Titel");
1095 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1096 expect(menu.shownItem(0).active()).toBe(false);
1097 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1098 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1099 expect(menu.shownItem(1).active()).toBe(false);
1100 expect(menu.shownItem(2)).toBe(undefined);
1101
1102
1103 // Forward
1104 menu.next();
1105 expect(menu.prefix()).toEqual("el");
1106 expect(menu._prefix.active()).toEqual(false);
1107 expect(menu.shownItem(0).name()).toEqual("Titel");
1108 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1109 expect(menu.shownItem(0).active()).toBe(true);
1110 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1111 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1112 expect(menu.shownItem(1).active()).toBe(false);
1113 expect(menu.shownItem(2)).toBe(undefined);
1114
1115 });
1116
1117 it('should show screens by offset', function () {
1118 var menu = KorAP.HintMenu.create('cnx/', demolist);
1119 menu.limit(3);
1120 expect(menu.show()).toBe(true);
1121
1122 expect(menu.shownItem(0).active()).toBe(false);
1123 expect(menu.shownItem(1).active()).toBe(false);
1124 expect(menu.shownItem(2).active()).toBe(false);
1125
1126 // Highlight the first entry
1127 menu.next();
1128
1129 expect(menu.shownItem(0).active()).toBe(true);
1130 expect(menu.shownItem(1).active()).toBe(false);
1131 expect(menu.shownItem(2).active()).toBe(false);
1132
1133 // Highlight the second entry
1134 menu.next();
1135
1136 expect(menu.shownItem(0).active()).toBe(false);
1137 expect(menu.shownItem(1).active()).toBe(true);
1138 expect(menu.shownItem(2).active()).toBe(false);
1139 expect(menu.shownItem(3)).toBe(undefined);
1140
1141 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1142 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1143
1144 // Move to first screen
1145 menu.screen(0);
1146 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1147 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1148 expect(menu.shownItem(0).active()).toBe(false);
1149 expect(menu.shownItem(1).active()).toBe(true);
1150 expect(menu.shownItem(2).active()).toBe(false);
1151 expect(menu.shownItem(3)).toBe(undefined);
1152
1153 // Move to second screen
1154 menu.screen(1);
1155 expect(menu.shownItem(0).lcField()).toEqual(' untertitel');
1156 expect(menu.shownItem(0).active()).toBe(true);
1157 expect(menu.shownItem(1).active()).toBe(false);
1158 expect(menu.shownItem(2).active()).toBe(false);
1159 expect(menu.shownItem(3)).toBe(undefined);
1160
1161 menu.screen(2);
1162 expect(menu.shownItem(0).lcField()).toEqual(' veröffentlichungsdatum');
1163 expect(menu.shownItem(0).active()).toBe(false);
1164 expect(menu.shownItem(1).active()).toBe(false);
1165 expect(menu.shownItem(2).active()).toBe(false);
1166 expect(menu.shownItem(3)).toBe(undefined);
1167
1168 menu.screen(1);
1169 expect(menu.shownItem(0).lcField()).toEqual(' untertitel');
1170 expect(menu.shownItem(0).active()).toBe(true);
1171 expect(menu.shownItem(1).active()).toBe(false);
1172 expect(menu.shownItem(2).active()).toBe(false);
1173 expect(menu.shownItem(3)).toBe(undefined);
1174 });
1175
1176 it('should show screens by offset when prefixed', function () {
1177 var menu = KorAP.HintMenu.create('cnx/', demolist);
1178 menu.limit(3);
1179 expect(menu.prefix("e").show()).toBe(true);
1180 expect(menu.shownItem(0).active()).toBe(false);
1181 expect(menu.shownItem(1).active()).toBe(false);
1182 expect(menu.shownItem(2).active()).toBe(false);
1183
1184 expect(menu.shownItem(0).element().innerHTML).toEqual('<strong>Tit<mark>e</mark>l</strong>');
1185 menu.screen(1);
1186 expect(menu.shownItem(0).element().innerHTML).toEqual('<strong>Unt<mark>e</mark>rtit<mark>e</mark>l</strong>');
1187 });
1188
1189
1190 it('should be page downable', function () {
1191 var menu = KorAP.OwnMenu.create(demolonglist);
1192 menu.limit(3);
1193
1194 expect(menu.show(0)).toBe(true);
1195
1196 expect(menu.shownItem(0).active()).toBe(true);
1197 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1198 expect(menu.shownItem(1).active()).toBe(false);
1199 expect(menu.shownItem(2).active()).toBe(false);
1200 expect(menu.shownItem(3)).toBe(undefined);
1201
1202 menu.pageDown();
1203
1204 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1205 expect(menu.shownItem(0).active()).toBe(false);
1206 expect(menu.shownItem(1).active()).toBe(false);
1207 expect(menu.shownItem(2).active()).toBe(false);
1208
1209 menu.pageDown();
1210
1211 expect(menu.shownItem(0).lcField()).toEqual(' corpusid');
1212 expect(menu.shownItem(0).active()).toBe(false);
1213 expect(menu.shownItem(1).active()).toBe(false);
1214 expect(menu.shownItem(2).active()).toBe(false);
1215
1216 // Doesn't matter
1217 menu.pageDown();
1218
1219 expect(menu.shownItem(0).lcField()).toEqual(' corpusid');
1220 expect(menu.shownItem(0).active()).toBe(false);
1221 expect(menu.shownItem(1).active()).toBe(false);
1222 expect(menu.shownItem(2).active()).toBe(false);
1223 });
1224
1225 it('should be page downable with prefix', function () {
1226 var menu = KorAP.OwnMenu.create(demolonglist);
1227 menu.limit(3);
1228
1229 expect(menu.prefix('e').show(0)).toBe(true);
1230
1231 expect(menu.shownItem(0).active()).toBe(true);
1232 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1233 expect(menu.shownItem(1).active()).toBe(false);
1234 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1235 expect(menu.shownItem(2).active()).toBe(false);
1236 expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum');
1237 expect(menu.shownItem(3)).toBe(undefined);
1238
1239 menu.pageDown();
1240
1241 expect(menu.shownItem(0).active()).toBe(false);
1242 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1243 expect(menu.shownItem(1).active()).toBe(false);
1244 expect(menu.shownItem(1).lcField()).toEqual(' genre');
1245 expect(menu.shownItem(2).active()).toBe(false);
1246 expect(menu.shownItem(2).lcField()).toEqual(' textid');
1247
1248 // Doesn't matter
1249 menu.pageDown();
1250
1251 expect(menu.shownItem(0).active()).toBe(false);
1252 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1253 expect(menu.shownItem(1).active()).toBe(false);
1254 expect(menu.shownItem(1).lcField()).toEqual(' genre');
1255 expect(menu.shownItem(2).active()).toBe(false);
1256 expect(menu.shownItem(2).lcField()).toEqual(' textid');
1257 });
1258
1259
1260 it('should be page upable', function () {
1261 var menu = KorAP.OwnMenu.create(demolonglist);
1262 menu.limit(3);
1263
1264 // Choose the final value
1265 expect(menu.show(1000)).toBe(true);
1266
1267 expect(menu.shownItem(0).active()).toBe(false);
1268 expect(menu.shownItem(1).active()).toBe(false);
1269 expect(menu.shownItem(2).active()).toBe(true);
1270 expect(menu.shownItem(2).lcField()).toEqual(' textid');
1271 expect(menu.shownItem(3)).toBe(undefined);
1272
1273 menu.pageUp();
1274
1275 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1276 expect(menu.shownItem(0).active()).toBe(false);
1277 expect(menu.shownItem(1).active()).toBe(false);
1278 expect(menu.shownItem(2).active()).toBe(false);
1279
1280 menu.pageUp();
1281
1282 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1283 expect(menu.shownItem(0).active()).toBe(false);
1284 expect(menu.shownItem(1).active()).toBe(false);
1285 expect(menu.shownItem(2).active()).toBe(false);
1286
1287 // Doesn't matter
1288 menu.pageUp();
1289
1290 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1291 expect(menu.shownItem(0).active()).toBe(false);
1292 expect(menu.shownItem(1).active()).toBe(false);
1293 expect(menu.shownItem(2).active()).toBe(false);
1294 });
1295
1296 it('should be page upable with prefix', function () {
1297 var menu = KorAP.OwnMenu.create(demolonglist);
1298 menu.limit(3);
1299
1300 // Choose the final value
1301 expect(menu.prefix("e").show(1000)).toBe(true);
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(true);
1308 expect(menu.shownItem(2).lcField()).toEqual(' textid');
1309 expect(menu.shownItem(3)).toBe(undefined);
1310
1311 menu.pageUp();
1312
1313 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1314 expect(menu.shownItem(0).active()).toBe(false);
1315 expect(menu.shownItem(1).active()).toBe(false);
1316 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1317 expect(menu.shownItem(2).active()).toBe(false);
1318 expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum');
1319
1320 // Doesn't matter
1321 menu.pageUp();
1322
1323 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1324 expect(menu.shownItem(0).active()).toBe(false);
1325 expect(menu.shownItem(1).active()).toBe(false);
1326 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1327 expect(menu.shownItem(2).active()).toBe(false);
1328 expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum');
1329 });
1330
1331 it('should scroll to a chosen value (1)', function () {
1332 var menu = KorAP.OwnMenu.create(demolist);
1333 menu.limit(3);
1334
1335 // Choose value 1
1336 expect(menu.show(1)).toBe(true);
1337
1338 expect(menu.shownItem(0).active()).toBe(false);
1339 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1340 expect(menu.shownItem(1).active()).toBe(true);
1341 expect(menu.shownItem(2).active()).toBe(false);
1342 expect(menu.shownItem(3)).toBe(undefined);
1343
1344 // Choose value 2
1345 expect(menu.show(2)).toBe(true);
1346
1347 expect(menu.shownItem(0).active()).toBe(false);
1348 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1349 expect(menu.shownItem(1).active()).toBe(false);
1350 expect(menu.shownItem(2).active()).toBe(true);
1351 expect(menu.shownItem(3)).toBe(undefined);
1352 });
1353
1354 it('should scroll to a chosen value (2)', function () {
1355 var menu = KorAP.OwnMenu.create(demolonglist);
1356
1357 // Choose value 3
1358 expect(menu.limit(3).show(3)).toBe(true);
1359 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1360 expect(menu.shownItem(0).active()).toBe(true);
1361 expect(menu.shownItem(1).active()).toBe(false);
1362 expect(menu.shownItem(2).active()).toBe(false);
1363 expect(menu.shownItem(3)).toBe(undefined);
1364 });
1365
1366 xit('should scroll to a chosen value after prefixing, if the chosen value is live');
1367 });
1368
1369 describe('KorAP.Prefix', function () {
1370 it('should be initializable', function () {
1371 var p = prefixClass.create();
1372 expect(p.element().classList.contains('pref')).toBeTruthy();
1373 expect(p.isSet()).not.toBeTruthy();
1374
1375 /*
1376 expect(mi.lcField()).toEqual(' baum');
1377 */
1378
1379 });
1380
1381 it('should be modifiable', function () {
1382 var p = prefixClass.create();
1383 expect(p.value()).toEqual('');
1384 expect(p.element().firstChild).toBeNull();
1385
1386 // Set string
1387 expect(p.value('Test')).toEqual('Test');
1388 expect(p.value()).toEqual('Test');
1389 expect(p.element().firstChild.nodeValue).toEqual('Test');
1390
1391 // Add string
1392 expect(p.add('ified')).toEqual('Testified');
1393 expect(p.value()).toEqual('Testified');
1394 expect(p.element().firstChild.nodeValue).toEqual('Testified');
1395
1396 // Clear string
1397 p.clear();
1398 expect(p.value()).toEqual('');
1399 expect(p.element().firstChild).toBeNull();
1400
1401 // Set string
1402 expect(p.value('Test')).toEqual('Test');
1403 expect(p.value()).toEqual('Test');
1404 expect(p.element().firstChild.nodeValue).toEqual('Test');
1405
1406 expect(p.chop()).toEqual('Tes');
1407 expect(p.value()).toEqual('Tes');
1408 expect(p.element().firstChild.nodeValue).toEqual('Tes');
1409
1410 expect(p.chop()).toEqual('Te');
1411 expect(p.value()).toEqual('Te');
1412 expect(p.element().firstChild.nodeValue).toEqual('Te');
1413
1414 expect(p.chop()).toEqual('T');
1415 expect(p.value()).toEqual('T');
1416 expect(p.element().firstChild.nodeValue).toEqual('T');
1417
1418 expect(p.chop()).toEqual('');
1419 expect(p.value()).toEqual('');
1420 expect(p.element().firstChild).toBeNull();
1421 });
1422
1423 it('should be activatable', function () {
1424 var p = prefixClass.create();
1425 expect(p.value()).toEqual('');
1426 expect(p.element().firstChild).toBeNull();
1427
1428 expect(p.value('Test')).toEqual('Test');
1429 expect(p.element().firstChild.nodeValue).toEqual('Test');
1430
1431 expect(p.active()).not.toBeTruthy();
1432 expect(p.element().classList.contains('active')).not.toBeTruthy();
1433
1434 p.active(true);
1435 expect(p.active()).toBeTruthy();
1436 expect(p.element().classList.contains('active')).toBeTruthy();
1437 });
1438 });
1439
1440 describe('KorAP.LengthField', function () {
1441 it('should be initializable', function () {
1442 var l = lengthFieldClass.create();
1443 expect(l.element().classList.contains('lengthField')).toBeTruthy();
1444 expect(l.element().children.length).toEqual(0);
1445 });
1446
1447 it('should be extensible', function () {
1448 var l = lengthFieldClass.create();
1449 l.add(['Baum']);
1450 expect(l.element().children.length).toEqual(1);
1451 expect(l.element().children[0].nodeName).toEqual('SPAN');
1452 expect(l.element().children[0].textContent).toEqual('Baum--');
1453 l.add(['Fragezeichen']);
1454 expect(l.element().children.length).toEqual(2);
1455 expect(l.element().children[1].nodeName).toEqual('SPAN');
1456 expect(l.element().children[1].textContent).toEqual('Fragezeichen--');
1457 });
1458
1459 it('should be correctly initializable', function () {
1460 var list = [
1461 ["Constituency"],
1462 ["Lemma"],
1463 ["Morphology"],
1464 ["Part-of-Speech"],
1465 ["Syntax"]
1466 ];
1467
1468 var menu = KorAP.OwnMenu.create(list);
1469
1470 expect(menu.lengthField().element().children.length).toEqual(5);
1471 });
1472 });
1473
1474 describe('KorAP.Slider', function () {
1475
1476 var demolonglist = [
1477 ['Titel', 'title'],
1478 ['Untertitel', 'subTitle'],
1479 ['Veröffentlichungsdatum', 'pubDate'],
1480 ['Länge', 'length'],
1481 ['Autor', 'author'],
1482 ['Genre', 'genre'],
1483 ['corpusID', 'corpusID'],
1484 ['docID', 'docID'],
1485 ['textID', 'textID'],
1486 ];
1487
1488 it('should correctly be initializable', function () {
1489 var list = [
1490 ["Constituency"],
1491 ["Lemma"],
1492 ["Morphology"],
1493 ["Part-of-Speech"],
1494 ["Syntax"]
1495 ];
1496
1497 var menu = KorAP.OwnMenu.create(list);
1498
1499 menu._firstActive = true;
1500 menu.limit(3);
1501
1502 expect(menu.show()).toBe(true);
1503
1504 expect(menu.shownItem(0).active()).toBe(true);
1505 expect(menu.shownItem(1).active()).toBe(false);
1506 expect(menu.shownItem(2).active()).toBe(false);
1507 expect(menu.slider().offset()).toEqual(0);
1508 expect(menu.position).toEqual(0);
1509 });
1510
1511 it('should correctly move on arrow keys', 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 menu._firstActive = true;
1523 menu.limit(3);
1524
1525 expect(menu.show()).toBe(true);
1526
1527 menu.next();
1528 expect(menu.shownItem(0).active()).toBe(false);
1529 expect(menu.shownItem(1).active()).toBe(true);
1530 expect(menu.shownItem(2).active()).toBe(false);
1531 expect(menu.slider().offset()).toEqual(0);
1532 expect(menu.position).toEqual(1);
1533
1534 menu.next();
1535 expect(menu.shownItem(0).active()).toBe(false);
1536 expect(menu.shownItem(1).active()).toBe(false);
1537 expect(menu.shownItem(2).active()).toBe(true);
1538 expect(menu.slider().offset()).toEqual(0);
1539 expect(menu.position).toEqual(2);
1540
1541 menu.next();
1542 expect(menu.shownItem(0).active()).toBe(false);
1543 expect(menu.shownItem(1).active()).toBe(false);
1544 expect(menu.shownItem(2).active()).toBe(true);
1545 expect(menu.slider().offset()).toEqual(1);
1546 expect(menu.position).toEqual(3);
1547
1548 menu.next();
1549 expect(menu.shownItem(0).active()).toBe(false);
1550 expect(menu.shownItem(1).active()).toBe(false);
1551 expect(menu.shownItem(2).active()).toBe(true);
1552 expect(menu.slider().offset()).toEqual(2);
1553 expect(menu.position).toEqual(4);
1554
1555 menu.next();
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 expect(menu.slider()._slider.style.height).toEqual('60%');
1563 });
1564
1565 it('should correctly resize on prefixing', function () {
1566 var menu = KorAP.OwnMenu.create(demolonglist);
1567 menu._firstActive = true;
1568 menu.limit(3);
1569
1570 expect(menu.show()).toBe(true);
1571 expect(menu.slider().offset()).toEqual(0);
1572 expect(menu.slider().length()).toEqual(9);
1573
1574 expect(menu.prefix("e").show()).toBe(true);
1575 expect(menu.slider().length()).toEqual(6);
1576
1577 expect(menu.prefix("el").show()).toBe(true);
1578 expect(menu.slider().length()).toEqual(2);
1579
1580 expect(menu.prefix("e").show()).toBe(true);
1581 expect(menu.slider().length()).toEqual(6);
1582
1583 expect(menu.prefix("").show()).toBe(true);
1584 expect(menu.slider().length()).toEqual(9);
1585 });
1586
1587
1588 it('should correctly move the list on mousemove', function () {
1589 var list = [
1590 ["Constituency"],
1591 ["Lemma"],
1592 ["Morphology"],
1593 ["Part-of-Speech"],
1594 ["Syntax"]
1595 ];
1596
1597 var menu = KorAP.OwnMenu.create(list);
1598
1599 menu._firstActive = true;
1600 menu.limit(3);
1601
1602 expect(menu.show()).toBe(true);
1603
1604 expect(menu.shownItem(0).active()).toBe(true);
1605 expect(menu.shownItem(1).active()).toBe(false);
1606 expect(menu.shownItem(2).active()).toBe(false);
1607 expect(menu.slider().offset()).toEqual(0);
1608
1609 // This will normally be done on
1610 menu.slider()._rulerHeight = 100;
1611 menu.slider()._sliderHeight = 40;
1612 menu.slider()._event.initOffset = 0;
1613 expect(menu.slider().length()).toEqual(5);
1614
1615 menu.slider().movetoRel(10);
1616 expect(menu.slider().offset()).toEqual(0);
1617
1618 expect(menu.shownItem(0).active()).toBe(true);
1619 expect(menu.shownItem(0).lcField()).toEqual(' constituency');
1620 menu.slider().movetoRel(24);
1621 expect(menu.slider().offset()).toEqual(0);
1622 menu.slider().movetoRel(25);
1623 expect(menu.slider().offset()).toEqual(0);
1624
1625 menu.slider().movetoRel(30);
1626 expect(menu.slider().offset()).toEqual(1);
1627 menu.slider().movetoRel(59);
1628 expect(menu.slider().offset()).toEqual(1);
1629 expect(menu.shownItem(0).active()).toBe(false);
1630 expect(menu.shownItem(0).lcField()).toEqual(' lemma');
1631
1632 // Everything > 60 is offset 2
1633 menu.slider().movetoRel(60);
1634 expect(menu.slider().offset()).toEqual(2);
1635 menu.slider().movetoRel(180);
1636 expect(menu.slider().offset()).toEqual(2);
1637 expect(menu.shownItem(0).active()).toBe(false);
1638 expect(menu.shownItem(0).lcField()).toEqual(' morphology');
1639
1640 expect(menu.shownItem(1).active()).toBe(false);
1641 expect(menu.shownItem(2).active()).toBe(false);
1642
1643 // When the active cursor moves again - scroll to viewport
1644 // cursor is before viewport
1645 menu.next();
1646 expect(menu.shownItem(0).active()).toBe(true);
1647 expect(menu.shownItem(0).lcField()).toEqual(' lemma');
1648 expect(menu.shownItem(1).active()).toBe(false);
1649 expect(menu.shownItem(2).active()).toBe(false);
1650
1651 menu.next();
1652 menu.next();
1653 expect(menu.shownItem(0).active()).toBe(false);
1654 expect(menu.shownItem(0).lcField()).toEqual(' lemma');
1655 expect(menu.shownItem(1).active()).toBe(false);
1656 expect(menu.shownItem(1).lcField()).toEqual(' morphology');
1657 expect(menu.shownItem(2).active()).toBe(true);
1658 expect(menu.shownItem(2).lcField()).toEqual(' part-of-speech');
1659
1660 menu.slider().movetoRel(0);
1661 expect(menu.slider().offset()).toEqual(0);
1662 expect(menu.shownItem(0).active()).toBe(false);
1663 expect(menu.shownItem(0).lcField()).toEqual(' constituency');
1664 expect(menu.shownItem(1).active()).toBe(false);
1665 expect(menu.shownItem(1).lcField()).toEqual(' lemma');
1666 expect(menu.shownItem(2).active()).toBe(false);
1667 expect(menu.shownItem(2).lcField()).toEqual(' morphology');
1668
1669 // cursor is after viewport
1670 menu.next();
1671 expect(menu.slider().offset()).toEqual(2);
1672 expect(menu.shownItem(0).active()).toBe(false);
1673 expect(menu.shownItem(0).lcField()).toEqual(' morphology');
1674 expect(menu.shownItem(1).active()).toBe(false);
1675 expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech');
1676 expect(menu.shownItem(2).active()).toBe(true);
1677 expect(menu.shownItem(2).lcField()).toEqual(' syntax');
1678
1679 menu.slider().movetoRel(0);
1680 expect(menu.slider().offset()).toEqual(0);
1681 expect(menu.shownItem(0).active()).toBe(false);
1682 expect(menu.shownItem(0).lcField()).toEqual(' constituency');
1683 expect(menu.shownItem(1).active()).toBe(false);
1684 expect(menu.shownItem(1).lcField()).toEqual(' lemma');
1685 expect(menu.shownItem(2).active()).toBe(false);
1686 expect(menu.shownItem(2).lcField()).toEqual(' morphology');
1687
1688 menu.prev();
1689 expect(menu.slider().offset()).toEqual(2);
1690 expect(menu.shownItem(0).lcField()).toEqual(' morphology');
1691 expect(menu.shownItem(0).active()).toBe(false);
1692 expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech');
1693 expect(menu.shownItem(1).active()).toBe(true);
1694 expect(menu.shownItem(2).lcField()).toEqual(' syntax');
1695 expect(menu.shownItem(2).active()).toBe(false);
1696
1697 menu.prev();
1698 menu.prev();
1699 expect(menu.slider().offset()).toEqual(1);
1700 expect(menu.shownItem(0).lcField()).toEqual(' lemma');
1701 expect(menu.shownItem(0).active()).toBe(true);
1702 expect(menu.shownItem(1).lcField()).toEqual(' morphology');
1703 expect(menu.shownItem(1).active()).toBe(false);
1704 expect(menu.shownItem(2).lcField()).toEqual(' part-of-speech');
1705 expect(menu.shownItem(2).active()).toBe(false);
1706
1707 menu.slider().movetoRel(100);
1708 expect(menu.slider().offset()).toEqual(2);
1709 expect(menu.shownItem(0).lcField()).toEqual(' morphology');
1710 expect(menu.shownItem(0).active()).toBe(false);
1711 expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech');
1712 expect(menu.shownItem(1).active()).toBe(false);
1713 expect(menu.shownItem(2).lcField()).toEqual(' syntax');
1714 expect(menu.shownItem(2).active()).toBe(false);
1715
1716 menu.prev();
1717 expect(menu.slider().offset()).toEqual(0);
1718 expect(menu.shownItem(0).lcField()).toEqual(' constituency');
1719 expect(menu.shownItem(0).active()).toBe(true);
1720 expect(menu.shownItem(1).lcField()).toEqual(' lemma');
1721 expect(menu.shownItem(1).active()).toBe(false);
1722 expect(menu.shownItem(2).lcField()).toEqual(' morphology');
1723 expect(menu.shownItem(2).active()).toBe(false);
1724 });
1725 });
1726
1727 describe('KorAP.MenuBenchmark', function () {
1728 var menu = menuClass.create([
1729 ['Titel', 'title'],
1730 ['Untertitel', 'subTitle'],
1731 ['Veröffentlichungsdatum', 'pubDate'],
1732 ['Länge', 'length'],
1733 ['Autor', 'author']
1734 ]);
1735
1736 menu.limit(3).show();
1737
1738 // Some actions
1739 menu.next();
1740 menu.next();
1741 menu.prev();
1742 menu.prev();
1743 menu.prev();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001744
Akron3c2730f2016-05-24 15:08:29 +02001745 menu.pageDown();
Akron3c2730f2016-05-24 15:08:29 +02001746 menu.pageUp();
1747
Akronaba7a5a2016-08-15 21:58:33 +02001748 // There is no fourth item in the list!
1749 menu.prefix('e').show(4);
Akron5a1f5bb2016-05-23 22:00:39 +02001750 menu.next();
1751 menu.next();
Akron5a1f5bb2016-05-23 22:00:39 +02001752 menu.prev();
1753 menu.prev();
Akron5a1f5bb2016-05-23 22:00:39 +02001754 menu.prev();
Akronf86eaea2016-05-13 18:02:27 +02001755 });
1756 });