blob: db3e96899a3bc75181d836e0656febcbc09537db [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
822 it('should choose prefix with failing prefix (1)', function () {
823 var menu = KorAP.HintMenu.create("cnx/", list);
824 menu.limit(2);
825 expect(menu.prefix("exit").show()).toBe(true);
826 expect(menu.element().querySelector('li')).toBe(null);
827 expect(menu.shownItem(0)).toBeUndefined();
828 expect(menu._prefix.active()).toBe(true);
829 });
830
831
832 it('should choose prefix with failing prefix (2)', function () {
833 var menu = KorAP.HintMenu.create("cnx/", list);
834 menu.limit(2);
835 expect(menu.show()).toBe(true);
836 expect(menu.prefix("exit").show()).toBe(true);
837 expect(menu.element().querySelector('li')).toBe(null);
838 expect(menu.shownItem(0)).toBeUndefined();
839 expect(menu._prefix.active()).toBe(true);
840 });
841
842 it('should ignore navigation with failing prefix', function () {
843 var menu = KorAP.HintMenu.create("cnx/", list);
844 menu.limit(2);
845 expect(menu.show()).toBe(true);
846
847 menu.next();
848
849 expect(menu.prefix("exit").show()).toBe(true);
850 expect(menu.element().querySelector('li')).toBe(null);
851 expect(menu.shownItem(0)).toBeUndefined();
852 expect(menu._prefix.active()).toBe(true);
853
854 menu.next();
855 expect(menu._prefix.active()).toBe(true);
856
857 menu.prev();
858 expect(menu._prefix.active()).toBe(true);
859
860 });
861
862 it('should be navigatable with prefix', function () {
863 var menu = KorAP.HintMenu.create("cnx/", demolist);
864 menu._firstActive = true;
865
866 menu.limit(3);
867
868 expect(menu.show()).toBe(true);
869 expect(menu.prefix()).toEqual("");
870
871 expect(menu.shownItem(0).name()).toEqual("Titel");
872 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
873 expect(menu.shownItem(0).active()).toBe(true);
874 expect(menu.shownItem(1).name()).toEqual("Untertitel");
875 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
876 expect(menu.shownItem(1).active()).toBe(false);
877 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
878 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
879 expect(menu.shownItem(2).active()).toBe(false);
880 expect(menu.shownItem(3)).toBe(undefined);
881
882 menu._prefix.add('a');
883 expect(menu.show()).toBe(true);
884 expect(menu.prefix()).toEqual("a");
885 expect(menu.shownItem(0).name()).toEqual("Autor");
886 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
887
888 menu._prefix.add('u');
889 expect(menu.show()).toBe(true);
890 expect(menu.prefix()).toEqual("au");
891 expect(menu.shownItem(0).name()).toEqual("Autor");
892 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong><mark>Au</mark>tor</strong>");
893
894 menu._prefix.chop();
895 expect(menu.show()).toBe(true);
896 expect(menu.prefix()).toEqual("a");
897 expect(menu.shownItem(0).name()).toEqual("Autor");
898 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
899
900 menu._prefix.chop();
901 expect(menu.show()).toBe(true);
902 expect(menu.prefix()).toEqual("");
903 expect(menu.shownItem(0).name()).toEqual("Titel");
904 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
905 expect(menu.shownItem(0).active()).toBe(true);
906 expect(menu.shownItem(1).name()).toEqual("Untertitel");
907 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
908 expect(menu.shownItem(1).active()).toBe(false);
909 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
910 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
911 expect(menu.shownItem(2).active()).toBe(false);
912 expect(menu.shownItem(3)).toBe(undefined);
913
914 // Forward
915 menu._prefix.chop();
916 expect(menu.show()).toBe(true);
917 expect(menu.prefix()).toEqual("");
918 expect(menu.shownItem(0).name()).toEqual("Titel");
919 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
920 expect(menu.shownItem(0).active()).toBe(true);
921 expect(menu.shownItem(1).name()).toEqual("Untertitel");
922 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
923 expect(menu.shownItem(1).active()).toBe(false);
924 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
925 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
926 expect(menu.shownItem(2).active()).toBe(false);
927
928 // Forward
929 menu.next();
930 expect(menu.prefix()).toEqual("");
931 expect(menu.shownItem(0).name()).toEqual("Titel");
932 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
933 expect(menu.shownItem(0).active()).toBe(false);
934 expect(menu.shownItem(1).name()).toEqual("Untertitel");
935 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
936 expect(menu.shownItem(1).active()).toBe(true);
937 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
938 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
939 expect(menu.shownItem(2).active()).toBe(false);
940 expect(menu.shownItem(3)).toBe(undefined);
941
942 // Forward
943 menu.next();
944 expect(menu.prefix()).toEqual("");
945 expect(menu.shownItem(0).name()).toEqual("Titel");
946 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
947 expect(menu.shownItem(0).active()).toBe(false);
948 expect(menu.shownItem(1).name()).toEqual("Untertitel");
949 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
950 expect(menu.shownItem(1).active()).toBe(false);
951 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
952 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
953 expect(menu.shownItem(2).active()).toBe(true);
954 expect(menu.shownItem(3)).toBe(undefined);
955
956 // Forward
957 menu.next();
958 expect(menu.prefix()).toEqual("");
959 expect(menu.shownItem(0).name()).toEqual("Untertitel");
960 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Untertitel</strong>");
961 expect(menu.shownItem(0).active()).toBe(false);
962 expect(menu.shownItem(1).name()).toEqual("Veröffentlichungsdatum");
963 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
964 expect(menu.shownItem(1).active()).toBe(false);
965 expect(menu.shownItem(2).name()).toEqual("Länge");
966 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Länge</strong>");
967 expect(menu.shownItem(2).active()).toBe(true);
968 expect(menu.shownItem(3)).toBe(undefined);
969
970 // Forward
971 menu.next();
972 expect(menu.prefix()).toEqual("");
973 expect(menu.shownItem(0).name()).toEqual("Veröffentlichungsdatum");
974 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
975 expect(menu.shownItem(0).active()).toBe(false);
976 expect(menu.shownItem(1).name()).toEqual("Länge");
977 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Länge</strong>");
978 expect(menu.shownItem(1).active()).toBe(false);
979 expect(menu.shownItem(2).name()).toEqual("Autor");
980 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Autor</strong>");
981 expect(menu.shownItem(2).active()).toBe(true);
982 expect(menu.shownItem(3)).toBe(undefined);
983
984 // Forward
985 menu.next();
986 expect(menu.prefix()).toEqual("");
987 expect(menu.shownItem(0).name()).toEqual("Titel");
988 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
989 expect(menu.shownItem(0).active()).toBe(true);
990 expect(menu.shownItem(1).name()).toEqual("Untertitel");
991 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
992 expect(menu.shownItem(1).active()).toBe(false);
993 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
994 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
995 expect(menu.shownItem(2).active()).toBe(false);
996 });
997
998
999 it('should be navigatable with a prefix (1)', function () {
1000 var menu = KorAP.HintMenu.create("cnx/", demolist);
1001 menu._firstActive = true;
1002
1003 menu.limit(3);
1004
1005 expect(menu.show()).toBe(true);
1006 expect(menu.prefix()).toEqual("");
1007
1008 // Add prefix in uppercase - but check in lowercase
1009 menu.prefix('El');
1010 expect(menu.show()).toBe(true);
1011
1012 expect(menu.prefix()).toEqual("El");
1013 expect(menu._prefix.active()).toEqual(false);
1014 expect(menu.shownItem(0).name()).toEqual("Titel");
1015 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1016 expect(menu.shownItem(0).active()).toBe(true);
1017 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1018 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1019 expect(menu.shownItem(1).active()).toBe(false);
1020 expect(menu.shownItem(2)).toBe(undefined);
1021
1022 // Forward
1023 menu.next();
1024 expect(menu.prefix()).toEqual("El");
1025 expect(menu._prefix.active()).toEqual(false);
1026 expect(menu.shownItem(0).name()).toEqual("Titel");
1027 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1028 expect(menu.shownItem(0).active()).toBe(false);
1029 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1030 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1031 expect(menu.shownItem(1).active()).toBe(true);
1032 expect(menu.shownItem(2)).toBe(undefined);
1033
1034 // Forward
1035 menu.next();
1036 expect(menu.prefix()).toEqual("El");
1037 expect(menu._prefix.active()).toEqual(true);
1038 expect(menu.shownItem(0).name()).toEqual("Titel");
1039 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1040 expect(menu.shownItem(0).active()).toBe(false);
1041 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1042 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1043 expect(menu.shownItem(1).active()).toBe(false);
1044 expect(menu.shownItem(2)).toBe(undefined);
1045
1046 // Backward
1047 menu.prev();
1048 expect(menu.prefix()).toEqual("El");
1049 expect(menu._prefix.active()).toEqual(false);
1050 expect(menu.shownItem(0).name()).toEqual("Titel");
1051 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1052 expect(menu.shownItem(0).active()).toBe(false);
1053
1054 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1055 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1056 expect(menu.shownItem(1).active()).toBe(true);
1057 expect(menu.shownItem(2)).toBe(undefined);
1058 });
1059
1060
1061 it('should be navigatable with a prefix (2)', function () {
1062 var menu = KorAP.HintMenu.create("cnx/", demolist);
1063 menu._firstActive = true;
1064
1065 menu.limit(3);
1066 expect(menu.show()).toBe(true);
1067 expect(menu.prefix()).toEqual("");
1068 menu.prefix('el');
1069 expect(menu.show()).toBe(true);
1070
1071 expect(menu.prefix()).toEqual("el");
1072 expect(menu._prefix.active()).toEqual(false);
1073 expect(menu.shownItem(0).name()).toEqual("Titel");
1074 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1075 expect(menu.shownItem(0).active()).toBe(true);
1076 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1077 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1078 expect(menu.shownItem(1).active()).toBe(false);
1079 expect(menu.shownItem(2)).toBe(undefined);
1080
1081 // Backward
1082 menu.prev();
1083 expect(menu._prefix.active()).toEqual(true);
1084
1085 expect(menu.shownItem(0).name()).toEqual("Titel");
1086 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1087 expect(menu.shownItem(0).active()).toBe(false);
1088
1089 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1090 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1091 expect(menu.shownItem(1).active()).toBe(false);
1092 expect(menu.shownItem(2)).toBe(undefined);
1093
1094 // Backward
1095 menu.prev();
1096 expect(menu._prefix.active()).toEqual(false);
1097 expect(menu.shownItem(0).name()).toEqual("Titel");
1098 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1099 expect(menu.shownItem(0).active()).toBe(false);
1100 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1101 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1102 expect(menu.shownItem(1).active()).toBe(true);
1103 expect(menu.shownItem(2)).toBe(undefined);
1104 });
1105
1106 it('should be navigatable with a prefix (3)', function () {
1107 var menu = KorAP.HintMenu.create("cnx/", demolist);
1108 menu._firstActive = true;
1109 menu.limit(3);
1110 expect(menu.show()).toBe(true);
1111 expect(menu.prefix()).toEqual("");
1112 menu.prefix('el');
1113 expect(menu.show()).toBe(true);
1114
1115 expect(menu.prefix()).toEqual("el");
1116 expect(menu._prefix.active()).toEqual(false);
1117 expect(menu.shownItem(0).name()).toEqual("Titel");
1118 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1119 expect(menu.shownItem(0).active()).toBe(true);
1120 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1121 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1122 expect(menu.shownItem(1).active()).toBe(false);
1123 expect(menu.shownItem(2)).toBe(undefined);
1124
1125 // Backward
1126 menu.prev();
1127 expect(menu._prefix.active()).toEqual(true);
1128 expect(menu.shownItem(0).name()).toEqual("Titel");
1129 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1130 expect(menu.shownItem(0).active()).toBe(false);
1131 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1132 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1133 expect(menu.shownItem(1).active()).toBe(false);
1134 expect(menu.shownItem(2)).toBe(undefined);
1135
1136
1137 // Forward
1138 menu.next();
1139 expect(menu.prefix()).toEqual("el");
1140 expect(menu._prefix.active()).toEqual(false);
1141 expect(menu.shownItem(0).name()).toEqual("Titel");
1142 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1143 expect(menu.shownItem(0).active()).toBe(true);
1144 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1145 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1146 expect(menu.shownItem(1).active()).toBe(false);
1147 expect(menu.shownItem(2)).toBe(undefined);
1148
1149 });
1150
1151 it('should show screens by offset', function () {
1152 var menu = KorAP.HintMenu.create('cnx/', demolist);
1153 menu.limit(3);
1154 expect(menu.show()).toBe(true);
1155
1156 expect(menu.shownItem(0).active()).toBe(false);
1157 expect(menu.shownItem(1).active()).toBe(false);
1158 expect(menu.shownItem(2).active()).toBe(false);
1159
1160 // Highlight the first entry
1161 menu.next();
1162
1163 expect(menu.shownItem(0).active()).toBe(true);
1164 expect(menu.shownItem(1).active()).toBe(false);
1165 expect(menu.shownItem(2).active()).toBe(false);
1166
1167 // Highlight the second entry
1168 menu.next();
1169
1170 expect(menu.shownItem(0).active()).toBe(false);
1171 expect(menu.shownItem(1).active()).toBe(true);
1172 expect(menu.shownItem(2).active()).toBe(false);
1173 expect(menu.shownItem(3)).toBe(undefined);
1174
1175 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1176 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1177
1178 // Move to first screen
1179 menu.screen(0);
1180 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1181 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1182 expect(menu.shownItem(0).active()).toBe(false);
1183 expect(menu.shownItem(1).active()).toBe(true);
1184 expect(menu.shownItem(2).active()).toBe(false);
1185 expect(menu.shownItem(3)).toBe(undefined);
1186
1187 // Move to second screen
1188 menu.screen(1);
1189 expect(menu.shownItem(0).lcField()).toEqual(' untertitel');
1190 expect(menu.shownItem(0).active()).toBe(true);
1191 expect(menu.shownItem(1).active()).toBe(false);
1192 expect(menu.shownItem(2).active()).toBe(false);
1193 expect(menu.shownItem(3)).toBe(undefined);
1194
1195 menu.screen(2);
1196 expect(menu.shownItem(0).lcField()).toEqual(' veröffentlichungsdatum');
1197 expect(menu.shownItem(0).active()).toBe(false);
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.screen(1);
1203 expect(menu.shownItem(0).lcField()).toEqual(' untertitel');
1204 expect(menu.shownItem(0).active()).toBe(true);
1205 expect(menu.shownItem(1).active()).toBe(false);
1206 expect(menu.shownItem(2).active()).toBe(false);
1207 expect(menu.shownItem(3)).toBe(undefined);
1208 });
1209
1210 it('should show screens by offset when prefixed', function () {
1211 var menu = KorAP.HintMenu.create('cnx/', demolist);
1212 menu.limit(3);
1213 expect(menu.prefix("e").show()).toBe(true);
1214 expect(menu.shownItem(0).active()).toBe(false);
1215 expect(menu.shownItem(1).active()).toBe(false);
1216 expect(menu.shownItem(2).active()).toBe(false);
1217
1218 expect(menu.shownItem(0).element().innerHTML).toEqual('<strong>Tit<mark>e</mark>l</strong>');
1219 menu.screen(1);
1220 expect(menu.shownItem(0).element().innerHTML).toEqual('<strong>Unt<mark>e</mark>rtit<mark>e</mark>l</strong>');
1221 });
1222
1223
1224 it('should be page downable', function () {
1225 var menu = KorAP.OwnMenu.create(demolonglist);
1226 menu.limit(3);
1227
1228 expect(menu.show(0)).toBe(true);
1229
1230 expect(menu.shownItem(0).active()).toBe(true);
1231 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1232 expect(menu.shownItem(1).active()).toBe(false);
1233 expect(menu.shownItem(2).active()).toBe(false);
1234 expect(menu.shownItem(3)).toBe(undefined);
1235
1236 menu.pageDown();
1237
1238 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1239 expect(menu.shownItem(0).active()).toBe(false);
1240 expect(menu.shownItem(1).active()).toBe(false);
1241 expect(menu.shownItem(2).active()).toBe(false);
1242
1243 menu.pageDown();
1244
1245 expect(menu.shownItem(0).lcField()).toEqual(' corpusid');
1246 expect(menu.shownItem(0).active()).toBe(false);
1247 expect(menu.shownItem(1).active()).toBe(false);
1248 expect(menu.shownItem(2).active()).toBe(false);
1249
1250 // Doesn't matter
1251 menu.pageDown();
1252
1253 expect(menu.shownItem(0).lcField()).toEqual(' corpusid');
1254 expect(menu.shownItem(0).active()).toBe(false);
1255 expect(menu.shownItem(1).active()).toBe(false);
1256 expect(menu.shownItem(2).active()).toBe(false);
1257 });
1258
1259 it('should be page downable with prefix', function () {
1260 var menu = KorAP.OwnMenu.create(demolonglist);
1261 menu.limit(3);
1262
1263 expect(menu.prefix('e').show(0)).toBe(true);
1264
1265 expect(menu.shownItem(0).active()).toBe(true);
1266 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1267 expect(menu.shownItem(1).active()).toBe(false);
1268 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1269 expect(menu.shownItem(2).active()).toBe(false);
1270 expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum');
1271 expect(menu.shownItem(3)).toBe(undefined);
1272
1273 menu.pageDown();
1274
1275 expect(menu.shownItem(0).active()).toBe(false);
1276 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1277 expect(menu.shownItem(1).active()).toBe(false);
1278 expect(menu.shownItem(1).lcField()).toEqual(' genre');
1279 expect(menu.shownItem(2).active()).toBe(false);
1280 expect(menu.shownItem(2).lcField()).toEqual(' textid');
1281
1282 // Doesn't matter
1283 menu.pageDown();
1284
1285 expect(menu.shownItem(0).active()).toBe(false);
1286 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1287 expect(menu.shownItem(1).active()).toBe(false);
1288 expect(menu.shownItem(1).lcField()).toEqual(' genre');
1289 expect(menu.shownItem(2).active()).toBe(false);
1290 expect(menu.shownItem(2).lcField()).toEqual(' textid');
1291 });
1292
1293
1294 it('should be page upable', function () {
1295 var menu = KorAP.OwnMenu.create(demolonglist);
1296 menu.limit(3);
1297
1298 // Choose the final value
1299 expect(menu.show(1000)).toBe(true);
1300
1301 expect(menu.shownItem(0).active()).toBe(false);
1302 expect(menu.shownItem(1).active()).toBe(false);
1303 expect(menu.shownItem(2).active()).toBe(true);
1304 expect(menu.shownItem(2).lcField()).toEqual(' textid');
1305 expect(menu.shownItem(3)).toBe(undefined);
1306
1307 menu.pageUp();
1308
1309 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1310 expect(menu.shownItem(0).active()).toBe(false);
1311 expect(menu.shownItem(1).active()).toBe(false);
1312 expect(menu.shownItem(2).active()).toBe(false);
1313
1314 menu.pageUp();
1315
1316 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1317 expect(menu.shownItem(0).active()).toBe(false);
1318 expect(menu.shownItem(1).active()).toBe(false);
1319 expect(menu.shownItem(2).active()).toBe(false);
1320
1321 // Doesn't matter
1322 menu.pageUp();
1323
1324 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1325 expect(menu.shownItem(0).active()).toBe(false);
1326 expect(menu.shownItem(1).active()).toBe(false);
1327 expect(menu.shownItem(2).active()).toBe(false);
1328 });
1329
1330 it('should be page upable with prefix', function () {
1331 var menu = KorAP.OwnMenu.create(demolonglist);
1332 menu.limit(3);
1333
1334 // Choose the final value
1335 expect(menu.prefix("e").show(1000)).toBe(true);
1336
1337 expect(menu.shownItem(0).active()).toBe(false);
1338 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1339 expect(menu.shownItem(1).active()).toBe(false);
1340 expect(menu.shownItem(1).lcField()).toEqual(' genre');
1341 expect(menu.shownItem(2).active()).toBe(true);
1342 expect(menu.shownItem(2).lcField()).toEqual(' textid');
1343 expect(menu.shownItem(3)).toBe(undefined);
1344
1345 menu.pageUp();
1346
1347 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1348 expect(menu.shownItem(0).active()).toBe(false);
1349 expect(menu.shownItem(1).active()).toBe(false);
1350 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1351 expect(menu.shownItem(2).active()).toBe(false);
1352 expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum');
1353
1354 // Doesn't matter
1355 menu.pageUp();
1356
1357 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1358 expect(menu.shownItem(0).active()).toBe(false);
1359 expect(menu.shownItem(1).active()).toBe(false);
1360 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1361 expect(menu.shownItem(2).active()).toBe(false);
1362 expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum');
1363 });
1364
1365 it('should scroll to a chosen value (1)', function () {
1366 var menu = KorAP.OwnMenu.create(demolist);
1367 menu.limit(3);
1368
1369 // Choose value 1
1370 expect(menu.show(1)).toBe(true);
1371
1372 expect(menu.shownItem(0).active()).toBe(false);
1373 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1374 expect(menu.shownItem(1).active()).toBe(true);
1375 expect(menu.shownItem(2).active()).toBe(false);
1376 expect(menu.shownItem(3)).toBe(undefined);
1377
1378 // Choose value 2
1379 expect(menu.show(2)).toBe(true);
1380
1381 expect(menu.shownItem(0).active()).toBe(false);
1382 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1383 expect(menu.shownItem(1).active()).toBe(false);
1384 expect(menu.shownItem(2).active()).toBe(true);
1385 expect(menu.shownItem(3)).toBe(undefined);
1386 });
1387
1388 it('should scroll to a chosen value (2)', function () {
1389 var menu = KorAP.OwnMenu.create(demolonglist);
1390
1391 // Choose value 3
1392 expect(menu.limit(3).show(3)).toBe(true);
1393 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1394 expect(menu.shownItem(0).active()).toBe(true);
1395 expect(menu.shownItem(1).active()).toBe(false);
1396 expect(menu.shownItem(2).active()).toBe(false);
1397 expect(menu.shownItem(3)).toBe(undefined);
1398 });
1399
1400 xit('should scroll to a chosen value after prefixing, if the chosen value is live');
1401 });
1402
1403 describe('KorAP.Prefix', function () {
1404 it('should be initializable', function () {
1405 var p = prefixClass.create();
1406 expect(p.element().classList.contains('pref')).toBeTruthy();
1407 expect(p.isSet()).not.toBeTruthy();
1408
1409 /*
1410 expect(mi.lcField()).toEqual(' baum');
1411 */
1412
1413 });
1414
1415 it('should be modifiable', function () {
1416 var p = prefixClass.create();
1417 expect(p.value()).toEqual('');
1418 expect(p.element().firstChild).toBeNull();
1419
1420 // Set string
1421 expect(p.value('Test')).toEqual('Test');
1422 expect(p.value()).toEqual('Test');
1423 expect(p.element().firstChild.nodeValue).toEqual('Test');
1424
1425 // Add string
1426 expect(p.add('ified')).toEqual('Testified');
1427 expect(p.value()).toEqual('Testified');
1428 expect(p.element().firstChild.nodeValue).toEqual('Testified');
1429
1430 // Clear string
1431 p.clear();
1432 expect(p.value()).toEqual('');
1433 expect(p.element().firstChild).toBeNull();
1434
1435 // Set string
1436 expect(p.value('Test')).toEqual('Test');
1437 expect(p.value()).toEqual('Test');
1438 expect(p.element().firstChild.nodeValue).toEqual('Test');
1439
1440 expect(p.chop()).toEqual('Tes');
1441 expect(p.value()).toEqual('Tes');
1442 expect(p.element().firstChild.nodeValue).toEqual('Tes');
1443
1444 expect(p.chop()).toEqual('Te');
1445 expect(p.value()).toEqual('Te');
1446 expect(p.element().firstChild.nodeValue).toEqual('Te');
1447
1448 expect(p.chop()).toEqual('T');
1449 expect(p.value()).toEqual('T');
1450 expect(p.element().firstChild.nodeValue).toEqual('T');
1451
1452 expect(p.chop()).toEqual('');
1453 expect(p.value()).toEqual('');
1454 expect(p.element().firstChild).toBeNull();
1455 });
1456
1457 it('should be activatable', function () {
1458 var p = prefixClass.create();
1459 expect(p.value()).toEqual('');
1460 expect(p.element().firstChild).toBeNull();
1461
1462 expect(p.value('Test')).toEqual('Test');
1463 expect(p.element().firstChild.nodeValue).toEqual('Test');
1464
1465 expect(p.active()).not.toBeTruthy();
1466 expect(p.element().classList.contains('active')).not.toBeTruthy();
1467
1468 p.active(true);
1469 expect(p.active()).toBeTruthy();
1470 expect(p.element().classList.contains('active')).toBeTruthy();
1471 });
1472 });
1473
1474 describe('KorAP.LengthField', function () {
1475 it('should be initializable', function () {
1476 var l = lengthFieldClass.create();
1477 expect(l.element().classList.contains('lengthField')).toBeTruthy();
1478 expect(l.element().children.length).toEqual(0);
1479 });
1480
1481 it('should be extensible', function () {
1482 var l = lengthFieldClass.create();
1483 l.add(['Baum']);
1484 expect(l.element().children.length).toEqual(1);
1485 expect(l.element().children[0].nodeName).toEqual('SPAN');
1486 expect(l.element().children[0].textContent).toEqual('Baum--');
1487 l.add(['Fragezeichen']);
1488 expect(l.element().children.length).toEqual(2);
1489 expect(l.element().children[1].nodeName).toEqual('SPAN');
1490 expect(l.element().children[1].textContent).toEqual('Fragezeichen--');
1491 });
1492
1493 it('should be correctly initializable', function () {
1494 var list = [
1495 ["Constituency"],
1496 ["Lemma"],
1497 ["Morphology"],
1498 ["Part-of-Speech"],
1499 ["Syntax"]
1500 ];
1501
1502 var menu = KorAP.OwnMenu.create(list);
1503
1504 expect(menu.lengthField().element().children.length).toEqual(5);
1505 });
1506 });
1507
1508 describe('KorAP.Slider', function () {
1509
1510 var demolonglist = [
1511 ['Titel', 'title'],
1512 ['Untertitel', 'subTitle'],
1513 ['Veröffentlichungsdatum', 'pubDate'],
1514 ['Länge', 'length'],
1515 ['Autor', 'author'],
1516 ['Genre', 'genre'],
1517 ['corpusID', 'corpusID'],
1518 ['docID', 'docID'],
1519 ['textID', 'textID'],
1520 ];
1521
1522 it('should correctly be initializable', function () {
1523 var list = [
1524 ["Constituency"],
1525 ["Lemma"],
1526 ["Morphology"],
1527 ["Part-of-Speech"],
1528 ["Syntax"]
1529 ];
1530
1531 var menu = KorAP.OwnMenu.create(list);
1532
1533 menu._firstActive = true;
1534 menu.limit(3);
1535
1536 expect(menu.show()).toBe(true);
1537
1538 expect(menu.shownItem(0).active()).toBe(true);
1539 expect(menu.shownItem(1).active()).toBe(false);
1540 expect(menu.shownItem(2).active()).toBe(false);
1541 expect(menu.slider().offset()).toEqual(0);
1542 expect(menu.position).toEqual(0);
1543 });
1544
1545 it('should correctly move on arrow keys', function () {
1546 var list = [
1547 ["Constituency"],
1548 ["Lemma"],
1549 ["Morphology"],
1550 ["Part-of-Speech"],
1551 ["Syntax"]
1552 ];
1553
1554 var menu = KorAP.OwnMenu.create(list);
1555
1556 menu._firstActive = true;
1557 menu.limit(3);
1558
1559 expect(menu.show()).toBe(true);
1560
1561 menu.next();
1562 expect(menu.shownItem(0).active()).toBe(false);
1563 expect(menu.shownItem(1).active()).toBe(true);
1564 expect(menu.shownItem(2).active()).toBe(false);
1565 expect(menu.slider().offset()).toEqual(0);
1566 expect(menu.position).toEqual(1);
1567
1568 menu.next();
1569 expect(menu.shownItem(0).active()).toBe(false);
1570 expect(menu.shownItem(1).active()).toBe(false);
1571 expect(menu.shownItem(2).active()).toBe(true);
1572 expect(menu.slider().offset()).toEqual(0);
1573 expect(menu.position).toEqual(2);
1574
1575 menu.next();
1576 expect(menu.shownItem(0).active()).toBe(false);
1577 expect(menu.shownItem(1).active()).toBe(false);
1578 expect(menu.shownItem(2).active()).toBe(true);
1579 expect(menu.slider().offset()).toEqual(1);
1580 expect(menu.position).toEqual(3);
1581
1582 menu.next();
1583 expect(menu.shownItem(0).active()).toBe(false);
1584 expect(menu.shownItem(1).active()).toBe(false);
1585 expect(menu.shownItem(2).active()).toBe(true);
1586 expect(menu.slider().offset()).toEqual(2);
1587 expect(menu.position).toEqual(4);
1588
1589 menu.next();
1590 expect(menu.shownItem(0).active()).toBe(true);
1591 expect(menu.shownItem(1).active()).toBe(false);
1592 expect(menu.shownItem(2).active()).toBe(false);
1593 expect(menu.slider().offset()).toEqual(0);
1594 expect(menu.position).toEqual(0);
1595
1596 expect(menu.slider()._slider.style.height).toEqual('60%');
1597 });
1598
1599 it('should correctly resize on prefixing', function () {
1600 var menu = KorAP.OwnMenu.create(demolonglist);
1601 menu._firstActive = true;
1602 menu.limit(3);
1603
1604 expect(menu.show()).toBe(true);
1605 expect(menu.slider().offset()).toEqual(0);
1606 expect(menu.slider().length()).toEqual(9);
1607
1608 expect(menu.prefix("e").show()).toBe(true);
1609 expect(menu.slider().length()).toEqual(6);
1610
1611 expect(menu.prefix("el").show()).toBe(true);
1612 expect(menu.slider().length()).toEqual(2);
1613
1614 expect(menu.prefix("e").show()).toBe(true);
1615 expect(menu.slider().length()).toEqual(6);
1616
1617 expect(menu.prefix("").show()).toBe(true);
1618 expect(menu.slider().length()).toEqual(9);
1619 });
1620
1621
1622 it('should correctly move the list on mousemove', function () {
1623 var list = [
1624 ["Constituency"],
1625 ["Lemma"],
1626 ["Morphology"],
1627 ["Part-of-Speech"],
1628 ["Syntax"]
1629 ];
1630
1631 var menu = KorAP.OwnMenu.create(list);
1632
1633 menu._firstActive = true;
1634 menu.limit(3);
1635
1636 expect(menu.show()).toBe(true);
1637
1638 expect(menu.shownItem(0).active()).toBe(true);
1639 expect(menu.shownItem(1).active()).toBe(false);
1640 expect(menu.shownItem(2).active()).toBe(false);
1641 expect(menu.slider().offset()).toEqual(0);
1642
1643 // This will normally be done on
1644 menu.slider()._rulerHeight = 100;
1645 menu.slider()._sliderHeight = 40;
1646 menu.slider()._event.initOffset = 0;
1647 expect(menu.slider().length()).toEqual(5);
1648
1649 menu.slider().movetoRel(10);
1650 expect(menu.slider().offset()).toEqual(0);
1651
1652 expect(menu.shownItem(0).active()).toBe(true);
1653 expect(menu.shownItem(0).lcField()).toEqual(' constituency');
1654 menu.slider().movetoRel(24);
1655 expect(menu.slider().offset()).toEqual(0);
1656 menu.slider().movetoRel(25);
1657 expect(menu.slider().offset()).toEqual(0);
1658
1659 menu.slider().movetoRel(30);
1660 expect(menu.slider().offset()).toEqual(1);
1661 menu.slider().movetoRel(59);
1662 expect(menu.slider().offset()).toEqual(1);
1663 expect(menu.shownItem(0).active()).toBe(false);
1664 expect(menu.shownItem(0).lcField()).toEqual(' lemma');
1665
1666 // Everything > 60 is offset 2
1667 menu.slider().movetoRel(60);
1668 expect(menu.slider().offset()).toEqual(2);
1669 menu.slider().movetoRel(180);
1670 expect(menu.slider().offset()).toEqual(2);
1671 expect(menu.shownItem(0).active()).toBe(false);
1672 expect(menu.shownItem(0).lcField()).toEqual(' morphology');
1673
1674 expect(menu.shownItem(1).active()).toBe(false);
1675 expect(menu.shownItem(2).active()).toBe(false);
1676
1677 // When the active cursor moves again - scroll to viewport
1678 // cursor is before viewport
1679 menu.next();
1680 expect(menu.shownItem(0).active()).toBe(true);
1681 expect(menu.shownItem(0).lcField()).toEqual(' lemma');
1682 expect(menu.shownItem(1).active()).toBe(false);
1683 expect(menu.shownItem(2).active()).toBe(false);
1684
1685 menu.next();
1686 menu.next();
1687 expect(menu.shownItem(0).active()).toBe(false);
1688 expect(menu.shownItem(0).lcField()).toEqual(' lemma');
1689 expect(menu.shownItem(1).active()).toBe(false);
1690 expect(menu.shownItem(1).lcField()).toEqual(' morphology');
1691 expect(menu.shownItem(2).active()).toBe(true);
1692 expect(menu.shownItem(2).lcField()).toEqual(' part-of-speech');
1693
1694 menu.slider().movetoRel(0);
1695 expect(menu.slider().offset()).toEqual(0);
1696 expect(menu.shownItem(0).active()).toBe(false);
1697 expect(menu.shownItem(0).lcField()).toEqual(' constituency');
1698 expect(menu.shownItem(1).active()).toBe(false);
1699 expect(menu.shownItem(1).lcField()).toEqual(' lemma');
1700 expect(menu.shownItem(2).active()).toBe(false);
1701 expect(menu.shownItem(2).lcField()).toEqual(' morphology');
1702
1703 // cursor is after viewport
1704 menu.next();
1705 expect(menu.slider().offset()).toEqual(2);
1706 expect(menu.shownItem(0).active()).toBe(false);
1707 expect(menu.shownItem(0).lcField()).toEqual(' morphology');
1708 expect(menu.shownItem(1).active()).toBe(false);
1709 expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech');
1710 expect(menu.shownItem(2).active()).toBe(true);
1711 expect(menu.shownItem(2).lcField()).toEqual(' syntax');
1712
1713 menu.slider().movetoRel(0);
1714 expect(menu.slider().offset()).toEqual(0);
1715 expect(menu.shownItem(0).active()).toBe(false);
1716 expect(menu.shownItem(0).lcField()).toEqual(' constituency');
1717 expect(menu.shownItem(1).active()).toBe(false);
1718 expect(menu.shownItem(1).lcField()).toEqual(' lemma');
1719 expect(menu.shownItem(2).active()).toBe(false);
1720 expect(menu.shownItem(2).lcField()).toEqual(' morphology');
1721
1722 menu.prev();
1723 expect(menu.slider().offset()).toEqual(2);
1724 expect(menu.shownItem(0).lcField()).toEqual(' morphology');
1725 expect(menu.shownItem(0).active()).toBe(false);
1726 expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech');
1727 expect(menu.shownItem(1).active()).toBe(true);
1728 expect(menu.shownItem(2).lcField()).toEqual(' syntax');
1729 expect(menu.shownItem(2).active()).toBe(false);
1730
1731 menu.prev();
1732 menu.prev();
1733 expect(menu.slider().offset()).toEqual(1);
1734 expect(menu.shownItem(0).lcField()).toEqual(' lemma');
1735 expect(menu.shownItem(0).active()).toBe(true);
1736 expect(menu.shownItem(1).lcField()).toEqual(' morphology');
1737 expect(menu.shownItem(1).active()).toBe(false);
1738 expect(menu.shownItem(2).lcField()).toEqual(' part-of-speech');
1739 expect(menu.shownItem(2).active()).toBe(false);
1740
1741 menu.slider().movetoRel(100);
1742 expect(menu.slider().offset()).toEqual(2);
1743 expect(menu.shownItem(0).lcField()).toEqual(' morphology');
1744 expect(menu.shownItem(0).active()).toBe(false);
1745 expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech');
1746 expect(menu.shownItem(1).active()).toBe(false);
1747 expect(menu.shownItem(2).lcField()).toEqual(' syntax');
1748 expect(menu.shownItem(2).active()).toBe(false);
1749
1750 menu.prev();
1751 expect(menu.slider().offset()).toEqual(0);
1752 expect(menu.shownItem(0).lcField()).toEqual(' constituency');
1753 expect(menu.shownItem(0).active()).toBe(true);
1754 expect(menu.shownItem(1).lcField()).toEqual(' lemma');
1755 expect(menu.shownItem(1).active()).toBe(false);
1756 expect(menu.shownItem(2).lcField()).toEqual(' morphology');
1757 expect(menu.shownItem(2).active()).toBe(false);
1758 });
1759 });
1760
1761 describe('KorAP.MenuBenchmark', function () {
1762 var menu = menuClass.create([
1763 ['Titel', 'title'],
1764 ['Untertitel', 'subTitle'],
1765 ['Veröffentlichungsdatum', 'pubDate'],
1766 ['Länge', 'length'],
1767 ['Autor', 'author']
1768 ]);
1769
1770 menu.limit(3).show();
1771
1772 // Some actions
1773 menu.next();
1774 menu.next();
1775 menu.prev();
1776 menu.prev();
1777 menu.prev();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001778
Akron3c2730f2016-05-24 15:08:29 +02001779 menu.pageDown();
Akron3c2730f2016-05-24 15:08:29 +02001780 menu.pageUp();
1781
Akronaba7a5a2016-08-15 21:58:33 +02001782 // There is no fourth item in the list!
1783 menu.prefix('e').show(4);
Akron5a1f5bb2016-05-23 22:00:39 +02001784 menu.next();
1785 menu.next();
Akron5a1f5bb2016-05-23 22:00:39 +02001786 menu.prev();
1787 menu.prev();
Akron5a1f5bb2016-05-23 22:00:39 +02001788 menu.prev();
Akronf86eaea2016-05-13 18:02:27 +02001789 });
1790 });