blob: 40d72e0261540f9e4eca9cb161db330f3955dc00 [file] [log] [blame]
Leo Reppd162b2e2021-06-30 13:51:07 +02001define(
2 ['containermenu', 'menu/item', 'menu/prefix', 'menu/lengthField','container/containeritem','container/container'],
3 function (containerMenuClass, menuItemClass, prefixClass, lengthFieldClass, containerItemClass, containerClass) {
4
5 // The OwnMenu item
6 const OwnMenuItem = {
7 create : function (params) {
8 return Object.create(menuItemClass).upgradeTo(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");
19
20 this._content = document.createTextNode(params[0]);
21 this._lcField = ' ' + this.content().textContent.toLowerCase();
22
23 return this;
24 }
25 };
26
27 /**
28 * Create own conainerItem class.
29 */
30 const OwnContainerItemClass = {
31 create : function () {
32 var obj = containerItemClass.create()
33 .upgradeTo(OwnContainerItemClass);
34 //._init();
35 obj.value="";
36 return obj;
37 },
38 add : function (letter) {
39 this.value+=letter;
40 },
41 clear : function () {
42 this.value = "";
43 },
44 further : function () {
45 this.value = this.value + this.value;
46 },
47 onclick : function () {
48 },
49 element : function () {
50 // already defined
51 if (this._el !== undefined) return this._el;
52
53 // Create list item
54 const li = document.createElement("li");
55 li.innerHTML="CI";
56
57 // Connect action
58 if (this["onclick"] !== undefined) {
59 li["onclick"] = this.onclick.bind(this);
60 };
61 return this._el = li;
62 }
63 };
64
65 //List of items.
66 var ExampleItemList = new Array;
67 ExampleItemList.push(OwnContainerItemClass.create());
68 ExampleItemList.push(OwnContainerItemClass.create());
69 ExampleItemList[0].value = "CIValue1 ";
70 ExampleItemList[1].value = "CIValue2 ";
71 ExampleItemList[0].element().innerHTML = "CIText1 ";
72 ExampleItemList[1].element().innerHTML = "CIText2 ";
73
74 //Own container class.
75 const OwnContainerClass = {
76 create : function (listOfContainerItems, params) {
77 //console.log(containerClass);
78 return containerClass.create(listOfContainerItems, params)
79 .upgradeTo(OwnContainerClass);
80 }
81 };
82
83 const OwnContainerMenu = {
84 create : function (list, containerList) {
85 const params = {
86 itemClass : OwnMenuItem,
87 prefixClass : prefixClass,
88 lengthFieldClass : lengthFieldClass,
89 containerClass : OwnContainerClass,
90 containerItemClass : OwnContainerItemClass
91 };
92 var obj = containerMenuClass.create(list,params,containerList)
93 .upgradeTo(OwnContainerMenu);
94 //._init(list, params);
95 return obj;
96 }
97 };
98
Leo Reppc66268e2021-10-28 11:44:35 +020099 describe('KorAP.ContainerMenu', function () {
Leo Reppd162b2e2021-06-30 13:51:07 +0200100
101 var list = [
102 ["Constituency"],
103 ["Lemma"],
104 ["Morphology"],
105 ["Part-of-Speech"],
106 ["Syntax"]
107 ];
108
109 var listWithEX = [
110 ["example 1 Constituency"],
111 ["Lemma"],
112 ["example 2 Morphology"],
113 ["Part-of_Speech"],
114 ["Syntax"]
115 ];
116
117 var listMultiPrefix = [
118 ["Personal Pronoun"],
119 ["Personal Pronoun, Plural"],
120 ["Personal Pronoun, Plural, Acc."],
121 ["Personal Pronoun, Plural, Dative"],
122 ["Personal Pronoun, Plural, Direct"],
123 ["Personal Pronoun, Plural, Oblique"],
124 ["Personal Pronoun, Singular"],
125 ["Personal Pronoun, Singular, Accusative"],
126 ["Personal Pronoun, Singular, Dative"],
127 ["Personal Pronoun, Singular, Direct"],
128 ["Personal Pronoun, Singular, Nominative"],
129 ["Personal Pronoun, Singular, Oblique"]
130 ];
131
132 var demolist = [
133 ['Titel'],
134 ['Untertitel'],
135 ['Veröffentlichungsdatum'],
136 ['Länge'],
137 ['Autor']
138 ];
139
140 var demolonglist = [
141 ['Titel'],
142 ['Untertitel'],
143 ['Veröffentlichungsdatum'],
144 ['Länge'],
145 ['Autor'],
146 ['Genre'],
147 ['corpusID'],
148 ['docID'],
149 ['textID'],
150 ];
151
152 it('should be initializable', function () {
153 /**var list = [
154 ["Constituency"],
155 ["Lemma"],
156 ["Morphology"],
157 ["Part-of-Speech"],
158 ["Syntax"]
159 ];
160 */
161
162 var menu = OwnContainerMenu.create(list,ExampleItemList);
163 // This is the same with and without additional container items!
164 expect(menu.dontHide).toBe(false);
165 menu._firstActive = true;
166 expect(menu.itemClass()).toEqual(OwnMenuItem);
167 expect(menu.element().nodeName).toEqual('UL');
168 expect(menu.element().classList.contains('visible')).toBeFalsy();
169 expect(menu.container().element().classList.contains('visible')).toBeFalsy();
170 expect(menu.limit()).toEqual(8);
171 expect(menu._notItemElements).toEqual(3);
172
173 menu.limit(9);
174 expect(menu.limit()).toEqual(9);
175
176 menu.limit(8);
177
178 // view
179 menu.show();
180 expect(menu.element().classList.contains('visible')).toBeTruthy();
181 expect(menu.container().element().classList.contains('visible')).toBeTruthy();
182
183 // First element in list
184 expect(menu.item(0).active()).toBe(true);
185 expect(menu.item(0).noMore()).toBe(true);
186
187 // Middle element in list
188 expect(menu.item(2).active()).toBe(false);
189 expect(menu.item(2).noMore()).toBe(false);
190
191 // Last element in list
192 expect(menu.item(menu.length() - 1).active()).toBe(false);
193 expect(menu.item(menu.length() - 1).noMore()).toBe(true);
194
195 expect(menu.element().classList.contains('containermenu')).toBeTruthy();
196 expect(menu.container()).toBeTruthy();
197 expect(menu._container.element().nodeName).toEqual('UL'); // actually need new one for container!
198 expect(menu._prefix.element().nodeName).toEqual('SPAN');
199 expect(menu._container._containerItemClass).toEqual(OwnContainerItemClass);
200 expect(menu._container.items.length).toEqual(3);
201 });
202
203 it('should have a reference to the menu', function () {
204 var menu = OwnContainerMenu.create(list,ExampleItemList);
205 expect(menu.item(0).menu()).toEqual(menu);
206 expect(menu.element().menu).toEqual(menu);
207 for (item of menu._container.items) {
208 expect(item._menu).toEqual(menu);
209 };
210 });
211
212
213 it('should be visible', function () {
214 var menu = OwnContainerMenu.create(list,ExampleItemList);
215 expect(menu.removeItems()).toBe(undefined);
216 menu.limit(3);
217
218 expect(menu.show()).toBe(true);
Leo Reppdedcf1a2021-08-18 18:57:47 +0200219 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200220 expect(liElements[0].innerHTML).toEqual("Constituency");
221 expect(liElements[1].innerHTML).toEqual("Lemma");
222 expect(liElements[2].innerHTML).toEqual("Morphology");
223 expect(liElements[3]).toBe(undefined);
224
225 // Check boundaries
226 expect(liElements[0].classList.contains("no-more")).toBe(true);
227 expect(liElements[1].classList.contains("no-more")).toBe(false);
228 expect(liElements[2].classList.contains("no-more")).toBe(false);
229
230 var items = menu.container().items;
231 expect(items[0].element().innerHTML).toEqual("CIText1 ");
232 expect(items[1].element().innerHTML).toEqual("CIText2 ");
233 expect(items[2].element().innerHTML).toEqual("");
234 expect(items[3]).toBe(undefined);
235 });
236
237 it('should be filterable', function () {
238 var menu = OwnContainerMenu.create(list,ExampleItemList);
239 menu.limit(3);
240 expect(menu.prefix("o").show()).toBe(true);
Leo Reppdedcf1a2021-08-18 18:57:47 +0200241 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200242 expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("o");
243 expect(liElements[0].innerHTML).toEqual("C<mark>o</mark>nstituency");
244 expect(liElements[1].innerHTML).toEqual("M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy");
245 expect(liElements[2].innerHTML).toEqual("Part-<mark>o</mark>f-Speech");
246 expect(liElements[3]).toBe(undefined);
247
248 // Check boundaries
249 expect(liElements[0].classList.contains("no-more")).toBe(true);
250 expect(liElements[1].classList.contains("no-more")).toBe(false);
251 expect(liElements[2].classList.contains("no-more")).toBe(true);
252
253 menu.limit(2);
254
255 expect(menu.prefix("o").show()).toBe(true);
Leo Reppdedcf1a2021-08-18 18:57:47 +0200256 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200257 expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("o");
258 expect(liElements[0].innerHTML).toEqual("C<mark>o</mark>nstituency");
259 expect(liElements[1].innerHTML).toEqual("M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy");
260
261 expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("o");
262 expect(liElements[2]).toBe(undefined);
263
264 // Check boundaries
265 expect(liElements[0].classList.contains("no-more")).toBe(true);
266 expect(liElements[1].classList.contains("no-more")).toBe(false);
267 expect(liElements[2]).toBe(undefined);
268
269 expect(menu.prefix("e").show()).toBe(true);
Leo Reppdedcf1a2021-08-18 18:57:47 +0200270 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200271 expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("e");
272 expect(liElements[0].innerHTML).toEqual("Constitu<mark>e</mark>ncy");
273 expect(liElements[2]).toBe(undefined);
274
275 menu.limit(5);
276 expect(menu.prefix("a").show()).toBe(true);
Leo Reppdedcf1a2021-08-18 18:57:47 +0200277 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200278 expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("a");
279 expect(liElements[0].innerHTML).toEqual("Lemm<mark>a</mark>");
280 expect(liElements[1].innerHTML).toEqual("P<mark>a</mark>rt-of-Speech");
281 expect(liElements[2].innerHTML).toEqual("Synt<mark>a</mark>x");
282 expect(liElements[3]).toBe(undefined);
283
284 });
Leo Repp050a7342021-10-25 11:05:32 +0200285
286 it('should switch to the containers prefix whenever the prefix filters the regular list to be empty', function () {
287 /**var list = [
288 ["Constituency"],
289 ["Lemma"],
290 ["Morphology"],
291 ["Part-of-Speech"],
292 ["Syntax"]
293 ];
294 */
295 var menu = OwnContainerMenu.create(list,ExampleItemList);
296 menu.container().add("1");
297 menu.show(); // Simulates Buttonpress 1
298 // See function _keypress in containermenu.js (line 147)
299 expect(menu.liveItem()).toBeUndefined(); // no elements in list match "1"
300 expect(menu.container().active()).toBeTruthy(); //thus switch to container
301 var liElements = directElementChildrenByTagName(menu.element(),"li");
302 expect(liElements).toEqual([]);
303 expect(menu.container().liveLength()).toEqual(3); //CI1 and 2, prefix
304 expect(menu._prefix.active()).toBeTruthy(); // HERE ONLY
305 // We want whichever container item was active before
306 // to stay active, default to prefix if none was.
307
308 //simulate _keydown(...) see containermenu.js line 137
309 menu.container().chop();
310 menu.show();
311 menu.prev();
312 expect(menu._prefix.active()).toBeFalsy();
313 expect(menu.container().item(1).active().toBeTruthy); // at location 1: CIItem 2
314 expect(menu.liveLength()).toEqual(5);
315
316 menu.container().add("1");
317 menu.show(); // Simulates Buttonpress 1
318 // See function _keypress in containermenu.js (line 147)
319 expect(menu.liveItem()).toBeUndefined(); // no elements in list match "1"
320 expect(menu.container().active()).toBeTruthy();
321 var liElements = directElementChildrenByTagName(menu.element(),"li");
322 expect(liElements).toEqual([]);
323 expect(menu.container().liveLength()).toEqual(3); //CI1 and 2, prefix
324 expect(menu.container().item(1).active().toBeTruthy); // at location 1: CIItem 2
325 // We want whichever container item was active before
326 // to stay active, default to prefix if none was.
327
328 });
Leo Reppd162b2e2021-06-30 13:51:07 +0200329
Leo Reppc66268e2021-10-28 11:44:35 +0200330 it('should allow removing an item from the container list', function () {/**var list = [
331 ["Constituency"],
332 ["Lemma"],
333 ["Morphology"],
334 ["Part-of-Speech"],
335 ["Syntax"]
336 ];
337 */
338 var menu = OwnContainerMenu.create(list,ExampleItemList);
339 menu._firstActive = true;
340 menu.limit(3);
341 expect(menu.show()).toBe(true);
342 menu.next();
343 menu.next();
344 menu.next();
345 menu.next();
346 expect(menu.shownItem(2).active()).toBe(true);
347 expect(menu.container().item(0).active()).toBe(false);
348 expect(menu.container().item(1).active()).toBe(false);
349 expect(menu.container().item(2).active()).toBe(false); //prefix
350 expect(menu.container().item(2)).toEqual(menu._prefix);
351 expect(menu.container().length()).toBe(3);
352 menu.container().removeItemByIndex(0);
353 expect(menu.shownItem(2).active()).toBe(true);
354 expect(menu.container().item(0).active()).toBe(false);
355 expect(menu.container().item(1).active()).toBe(false); //prefix
356 expect(menu.container().item(1)).toEqual(menu._prefix);
357 expect(menu.container().length()).toBe(2);
358 menu.next();
359 expect(menu.shownItem(2).active()).toBe(false);
360 expect(menu.container().item(0).active()).toBe(true);
361 expect(menu.container().item(1).active()).toBe(false); //prefix
362 expect(menu.container().item(1)).toEqual(menu._prefix);
363 expect(menu.container().length()).toBe(2);
364 menu.container().removeItemByIndex(0);
365 expect(menu.shownItem(2).active()).toBe(false);
366 expect(menu.shownItem(0).active()).toBe(true);
367 expect(menu.container().item(0).active()).toBe(false); //prefix //would be selected, if it were not ""
368 expect(menu.container().item(0)).toEqual(menu._prefix);
369 expect(menu.container().length()).toBe(1);
370
371
372
373 });
Leo Reppd162b2e2021-06-30 13:51:07 +0200374 it('should be nextable', function () {
375 var menu = OwnContainerMenu.create(list);
376 menu._firstActive = true;
377
378 // Show only 3 items
379 menu.limit(3);
380 expect(menu.show()).toBe(true);
Leo Reppdedcf1a2021-08-18 18:57:47 +0200381 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200382 expect(liElements[0].innerHTML).toEqual("Constituency");
383 expect(menu.shownItem(0).active()).toBe(true);
384 expect(liElements[1].innerHTML).toEqual("Lemma");
385 expect(menu.shownItem(1).active()).toBe(false);
386 expect(liElements[2].innerHTML).toEqual("Morphology");
387 expect(menu.shownItem(2).active()).toBe(false);
388 expect(liElements[3]).toBe(undefined);
389
390 // Activate next (1)
391 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200392 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200393 expect(liElements[0].innerHTML).toEqual("Constituency");
394 expect(menu.shownItem(0).active()).toBe(false);
395 expect(liElements[1].innerHTML).toEqual("Lemma");
396 expect(menu.shownItem(1).active()).toBe(true);
397 expect(liElements[2].innerHTML).toEqual("Morphology");
398 expect(menu.shownItem(2).active()).toBe(false);
399 expect(liElements[3]).toBe(undefined);
400
401 // Activate next (2)
402 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200403 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200404 expect(liElements[0].innerHTML).toEqual("Constituency");
405 expect(menu.shownItem(0).active()).toBe(false);
406 expect(liElements[1].innerHTML).toEqual("Lemma");
407 expect(menu.shownItem(1).active()).toBe(false);
408 expect(liElements[2].innerHTML).toEqual("Morphology");
409 expect(menu.shownItem(2).active()).toBe(true);
410 expect(liElements[3]).toBe(undefined);
411
412 // Activate next (3)
413 // scroll!
414 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200415 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200416 expect(liElements[0].innerHTML).toEqual("Lemma");
417 expect(menu.shownItem(0).active()).toBe(false);
418 expect(liElements[1].innerHTML).toEqual("Morphology");
419 expect(menu.shownItem(1).active()).toBe(false);
420 expect(liElements[2].innerHTML).toEqual("Part-of-Speech");
421 expect(menu.shownItem(2).active()).toBe(true);
422 expect(liElements[3]).toBe(undefined);
423
424 // Activate next (4)
425 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200426 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200427 expect(liElements[0].innerHTML).toEqual("Morphology");
428 expect(menu.shownItem(0).active()).toBe(false);
429 expect(liElements[1].innerHTML).toEqual("Part-of-Speech");
430 expect(menu.shownItem(1).active()).toBe(false);
431 expect(liElements[2].innerHTML).toEqual("Syntax");
432 expect(menu.shownItem(2).active()).toBe(true);
433 expect(liElements[3]).toBe(undefined);
434
435 // Activate next (5) - ROLL
436 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200437 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200438 expect(liElements[0].innerHTML).toEqual("Constituency");
439 expect(menu.shownItem(0).active()).toBe(true);
440 expect(liElements[1].innerHTML).toEqual("Lemma");
441 expect(menu.shownItem(1).active()).toBe(false);
442 expect(liElements[2].innerHTML).toEqual("Morphology");
443 expect(menu.shownItem(2).active()).toBe(false);
444 expect(liElements[3]).toBe(undefined);
445
446 // Active next (6)
447 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200448 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200449 expect(liElements[0].innerHTML).toEqual("Constituency");
450 expect(menu.shownItem(0).active()).toBe(false);
451 expect(liElements[1].innerHTML).toEqual("Lemma");
452 expect(menu.shownItem(1).active()).toBe(true);
453 expect(liElements[2].innerHTML).toEqual("Morphology");
454 expect(menu.shownItem(2).active()).toBe(false);
455 expect(liElements[3]).toBe(undefined);
456 });
457
458 it('should be nextable when there are two containeritems', function () {
459 var menu = OwnContainerMenu.create(list,ExampleItemList);
460 menu._firstActive = true;
461
462 // Show only 3 items
463 menu.limit(3);
464 expect(menu.show()).toBe(true);
Leo Reppdedcf1a2021-08-18 18:57:47 +0200465 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200466 expect(liElements[0].innerHTML).toEqual("Constituency");
467 expect(menu.shownItem(0).active()).toBe(true);
468 expect(liElements[1].innerHTML).toEqual("Lemma");
469 expect(menu.shownItem(1).active()).toBe(false);
470 expect(liElements[2].innerHTML).toEqual("Morphology");
471 expect(menu.shownItem(2).active()).toBe(false);
472 expect(liElements[3]).toBe(undefined);
473 expect(menu.container().items[0].active()).toBe(false);
474 expect(menu.container().items[1].active()).toBe(false);
475 expect(menu.container().items[2].active()).toBe(false); //prefix
476
477 // Activate next (1)
478 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200479 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200480 expect(liElements[0].innerHTML).toEqual("Constituency");
481 expect(menu.shownItem(0).active()).toBe(false);
482 expect(liElements[1].innerHTML).toEqual("Lemma");
483 expect(menu.shownItem(1).active()).toBe(true);
484 expect(liElements[2].innerHTML).toEqual("Morphology");
485 expect(menu.shownItem(2).active()).toBe(false);
486 expect(liElements[3]).toBe(undefined);
487 expect(menu.container().items[0].active()).toBe(false);
488 expect(menu.container().items[1].active()).toBe(false);
489 expect(menu.container().items[2].active()).toBe(false); //prefix
490
491 // Activate next (2)
492 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200493 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200494 expect(liElements[0].innerHTML).toEqual("Constituency");
495 expect(menu.shownItem(0).active()).toBe(false);
496 expect(liElements[1].innerHTML).toEqual("Lemma");
497 expect(menu.shownItem(1).active()).toBe(false);
498 expect(liElements[2].innerHTML).toEqual("Morphology");
499 expect(menu.shownItem(2).active()).toBe(true);
500 expect(liElements[3]).toBe(undefined);
501 expect(menu.container().items[0].active()).toBe(false);
502 expect(menu.container().items[1].active()).toBe(false);
503 expect(menu.container().items[2].active()).toBe(false); //prefix
504
505 // Activate next (3)
506 // scroll!
507 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200508 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200509 expect(liElements[0].innerHTML).toEqual("Lemma");
510 expect(menu.shownItem(0).active()).toBe(false);
511 expect(liElements[1].innerHTML).toEqual("Morphology");
512 expect(menu.shownItem(1).active()).toBe(false);
513 expect(liElements[2].innerHTML).toEqual("Part-of-Speech");
514 expect(menu.shownItem(2).active()).toBe(true);
515 expect(liElements[3]).toBe(undefined);
516 expect(menu.container().items[0].active()).toBe(false);
517 expect(menu.container().items[1].active()).toBe(false);
518 expect(menu.container().items[2].active()).toBe(false); //prefix
519
520 // Activate next (4)
521 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200522 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200523 expect(liElements[0].innerHTML).toEqual("Morphology");
524 expect(menu.shownItem(0).active()).toBe(false);
525 expect(liElements[1].innerHTML).toEqual("Part-of-Speech");
526 expect(menu.shownItem(1).active()).toBe(false);
527 expect(liElements[2].innerHTML).toEqual("Syntax");
528 expect(menu.shownItem(2).active()).toBe(true);
529 expect(liElements[3]).toBe(undefined);
530 expect(menu.container().items[0].active()).toBe(false);
531 expect(menu.container().items[1].active()).toBe(false);
532 expect(menu.container().items[2].active()).toBe(false); //prefix
533
534 // Activate next (4.1) - Jump to container part
535 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200536 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200537 expect(liElements[0].innerHTML).toEqual("Morphology");
538 expect(menu.shownItem(0).active()).toBe(false);
539 expect(liElements[1].innerHTML).toEqual("Part-of-Speech");
540 expect(menu.shownItem(1).active()).toBe(false);
541 expect(liElements[2].innerHTML).toEqual("Syntax");
542 expect(menu.shownItem(2).active()).toBe(false);
543 expect(liElements[3]).toBe(undefined);
544 expect(menu.container().items[0].active()).toBe(true);
545 expect(menu.container().items[1].active()).toBe(false);
546 expect(menu.container().items[2].active()).toBe(false); //prefix
547
548 // Activate next (4.2)
549 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200550 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200551 expect(liElements[0].innerHTML).toEqual("Morphology");
552 expect(menu.shownItem(0).active()).toBe(false);
553 expect(liElements[1].innerHTML).toEqual("Part-of-Speech");
554 expect(menu.shownItem(1).active()).toBe(false);
555 expect(liElements[2].innerHTML).toEqual("Syntax");
556 expect(menu.shownItem(2).active()).toBe(false);
557 expect(liElements[3]).toBe(undefined);
558 expect(menu.container().items[0].active()).toBe(false);
559 expect(menu.container().items[1].active()).toBe(true);
560 expect(menu.container().items[2].active()).toBe(false); //prefix
561
562 /** Prefix is not set
563 // Activate next (4.3)
564 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200565 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200566 expect(liElements[0].innerHTML).toEqual("Morphology");
567 expect(menu.shownItem(0).active()).toBe(false);
568 expect(liElements[1].innerHTML).toEqual("Part-of-Speech");
569 expect(menu.shownItem(1).active()).toBe(false);
570 expect(liElements[2].innerHTML).toEqual("Syntax");
571 expect(menu.shownItem(2).active()).toBe(true);
572 expect(liElements[3]).toBe(undefined);
573 expect(menu.container().items[0].active()).toBe(false);
574 expect(menu.container().items[1].active()).toBe(false);
575 expect(menu.container().items[2].active()).toBe(true); //prefix
576 */
577
578 // Activate next (5) - ROLL
579 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200580 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200581 expect(liElements[0].innerHTML).toEqual("Constituency");
582 expect(menu.shownItem(0).active()).toBe(true);
583 expect(liElements[1].innerHTML).toEqual("Lemma");
584 expect(menu.shownItem(1).active()).toBe(false);
585 expect(liElements[2].innerHTML).toEqual("Morphology");
586 expect(menu.shownItem(2).active()).toBe(false);
587 expect(liElements[3]).toBe(undefined);
588 expect(menu.container().items[0].active()).toBe(false);
589 expect(menu.container().items[1].active()).toBe(false);
590 expect(menu.container().items[2].active()).toBe(false); //prefix
591
592 // Active next (6)
593 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200594 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200595 expect(liElements[0].innerHTML).toEqual("Constituency");
596 expect(menu.shownItem(0).active()).toBe(false);
597 expect(liElements[1].innerHTML).toEqual("Lemma");
598 expect(menu.shownItem(1).active()).toBe(true);
599 expect(liElements[2].innerHTML).toEqual("Morphology");
600 expect(menu.shownItem(2).active()).toBe(false);
601 expect(liElements[3]).toBe(undefined);
602 expect(menu.container().items[0].active()).toBe(false);
603 expect(menu.container().items[1].active()).toBe(false);
604 expect(menu.container().items[2].active()).toBe(false); //prefix
605 });
606
607 it('should be nextable without active field', function () {
608 var menu = OwnContainerMenu.create(list,ExampleItemList);
609 menu.limit(3);
610 expect(menu.show()).toBe(true);
611 menu.next();
612 expect(menu.shownItem(0).active()).toEqual(true);
613 });
614
615
616 it('should be prevable', function () {
617 var menu = OwnContainerMenu.create(list);
618 menu._firstActive = true;
619 menu.limit(3);
620 expect(menu.show()).toBe(true);
621
Leo Reppdedcf1a2021-08-18 18:57:47 +0200622 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200623 expect(liElements[0].innerHTML).toEqual("Constituency");
624 expect(menu.shownItem(0).active()).toBe(true);
625 expect(liElements[1].innerHTML).toEqual("Lemma");
626 expect(menu.shownItem(1).active()).toBe(false);
627 expect(liElements[2].innerHTML).toEqual("Morphology");
628 expect(menu.shownItem(2).active()).toBe(false);
629 expect(liElements[3]).toBe(undefined);
630
631 // Activate prev (1) - roll to bottom
632 menu.prev();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200633 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200634 expect(liElements[0].innerHTML).toEqual("Morphology");
635 expect(menu.shownItem(0).active()).toBe(false);
636 expect(liElements[1].innerHTML).toEqual("Part-of-Speech");
637 expect(menu.shownItem(1).active()).toBe(false);
638 expect(liElements[2].innerHTML).toEqual("Syntax");
639 expect(menu.shownItem(2).active()).toBe(true);
640 expect(liElements[3]).toBe(undefined);
641
642 // Activate prev (2)
643 menu.prev();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200644 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200645 expect(liElements[0].innerHTML).toEqual("Morphology");
646 expect(menu.shownItem(0).active()).toBe(false);
647 expect(liElements[1].innerHTML).toEqual("Part-of-Speech");
648 expect(menu.shownItem(1).active()).toBe(true);
649 expect(liElements[2].innerHTML).toEqual("Syntax");
650 expect(menu.shownItem(2).active()).toBe(false);
651 expect(liElements[3]).toBe(undefined);
652
653 // Activate prev (3)
654 menu.prev();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200655 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200656 expect(liElements[0].innerHTML).toEqual("Morphology");
657 expect(menu.shownItem(0).active()).toBe(true);
658 expect(liElements[1].innerHTML).toEqual("Part-of-Speech");
659 expect(menu.shownItem(1).active()).toBe(false);
660 expect(liElements[2].innerHTML).toEqual("Syntax");
661 expect(menu.shownItem(2).active()).toBe(false);
662 expect(liElements[3]).toBe(undefined);
663
664 // Activate prev (4)
665 menu.prev();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200666 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200667 expect(liElements[0].innerHTML).toEqual("Lemma");
668 expect(menu.shownItem(0).active()).toBe(true);
669 expect(liElements[1].innerHTML).toEqual("Morphology");
670 expect(menu.shownItem(1).active()).toBe(false);
671 expect(liElements[2].innerHTML).toEqual("Part-of-Speech");
672 expect(menu.shownItem(2).active()).toBe(false);
673 expect(liElements[3]).toBe(undefined);
674
675 // Activate prev (5)
676 menu.prev();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200677 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200678 expect(liElements[0].innerHTML).toEqual("Constituency");
679 expect(menu.shownItem(0).active()).toBe(true);
680 expect(liElements[1].innerHTML).toEqual("Lemma");
681 expect(menu.shownItem(1).active()).toBe(false);
682 expect(liElements[2].innerHTML).toEqual("Morphology");
683 expect(menu.shownItem(2).active()).toBe(false);
684 expect(liElements[3]).toBe(undefined);
685
686 // Activate next (1)
687 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200688 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200689 expect(liElements[0].innerHTML).toEqual("Constituency");
690 expect(menu.shownItem(0).active()).toBe(false);
691 expect(liElements[1].innerHTML).toEqual("Lemma");
692 expect(menu.shownItem(1).active()).toBe(true);
693 expect(liElements[2].innerHTML).toEqual("Morphology");
694 expect(menu.shownItem(2).active()).toBe(false);
695 expect(liElements[3]).toBe(undefined);
696
697 // Activate prev (6)
698 menu.prev();
699
700 // Activate prev (7)
701 menu.prev();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200702 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200703 expect(liElements[0].innerHTML).toEqual("Morphology");
704 expect(menu.shownItem(0).active()).toBe(false);
705 expect(liElements[1].innerHTML).toEqual("Part-of-Speech");
706 expect(menu.shownItem(1).active()).toBe(false);
707 expect(liElements[2].innerHTML).toEqual("Syntax");
708 expect(menu.shownItem(2).active()).toBe(true);
709 expect(liElements[3]).toBe(undefined);
710 });
711
712 it('should be prevable with containerItems', function () {
713 var menu = OwnContainerMenu.create(list,ExampleItemList);
714 menu._firstActive = true;
715 menu.limit(3);
716 expect(menu.show()).toBe(true);
Leo Reppdedcf1a2021-08-18 18:57:47 +0200717 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200718 expect(liElements[0].innerHTML).toEqual("Constituency");
719 expect(menu.shownItem(0).active()).toBe(true);
720 expect(liElements[1].innerHTML).toEqual("Lemma");
721 expect(menu.shownItem(1).active()).toBe(false);
722 expect(liElements[2].innerHTML).toEqual("Morphology");
723 expect(menu.shownItem(2).active()).toBe(false);
724 expect(liElements[3]).toBe(undefined);
725 expect(menu.container().items[0].active()).toBe(false);
726 expect(menu.container().items[1].active()).toBe(false);
727 expect(menu.container().items[2].active()).toBe(false); //prefix
728
729 // Activate prev (1) - roll to bottom - base items stay, now container
730 menu.prev();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200731 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200732 expect(liElements[0].innerHTML).toEqual("Constituency");
733 expect(menu.shownItem(0).active()).toBe(false);
734 expect(liElements[1].innerHTML).toEqual("Lemma");
735 expect(menu.shownItem(1).active()).toBe(false);
736 expect(liElements[2].innerHTML).toEqual("Morphology");
737 expect(menu.shownItem(2).active()).toBe(false);
738 expect(liElements[3]).toBe(undefined);
739 expect(menu.container().items[0].active()).toBe(false);
740 expect(menu.container().items[1].active()).toBe(true);
741 expect(menu.container().items[2].active()).toBe(false); //prefix
742
743 // Activate prev(2) - next container item
744 menu.prev();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200745 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200746 expect(liElements[0].innerHTML).toEqual("Constituency");
747 expect(menu.shownItem(0).active()).toBe(false);
748 expect(liElements[1].innerHTML).toEqual("Lemma");
749 expect(menu.shownItem(1).active()).toBe(false);
750 expect(liElements[2].innerHTML).toEqual("Morphology");
751 expect(menu.shownItem(2).active()).toBe(false);
752 expect(liElements[3]).toBe(undefined);
753 expect(menu.container().items[0].active()).toBe(true);
754 expect(menu.container().items[1].active()).toBe(false);
755 expect(menu.container().items[2].active()).toBe(false); //prefix
756
757 // Activate prev (3) - roll to bottom of normal list
758 menu.prev();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200759 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200760 expect(liElements[0].innerHTML).toEqual("Morphology");
761 expect(menu.shownItem(0).active()).toBe(false);
762 expect(liElements[1].innerHTML).toEqual("Part-of-Speech");
763 expect(menu.shownItem(1).active()).toBe(false);
764 expect(liElements[2].innerHTML).toEqual("Syntax");
765 expect(menu.shownItem(2).active()).toBe(true);
766 expect(liElements[3]).toBe(undefined);
767 expect(menu.container().items[0].active()).toBe(false);
768 expect(menu.container().items[1].active()).toBe(false);
769 expect(menu.container().items[2].active()).toBe(false); //prefix
770
771 // Activate prev (4)
772 menu.prev();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200773 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200774 expect(liElements[0].innerHTML).toEqual("Morphology");
775 expect(menu.shownItem(0).active()).toBe(false);
776 expect(liElements[1].innerHTML).toEqual("Part-of-Speech");
777 expect(menu.shownItem(1).active()).toBe(true);
778 expect(liElements[2].innerHTML).toEqual("Syntax");
779 expect(menu.shownItem(2).active()).toBe(false);
780 expect(liElements[3]).toBe(undefined);
781 expect(menu.container().items[0].active()).toBe(false);
782 expect(menu.container().items[1].active()).toBe(false);
783 expect(menu.container().items[2].active()).toBe(false); //prefix
784
785 // Activate prev (5)
786 menu.prev();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200787 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200788 expect(liElements[0].innerHTML).toEqual("Morphology");
789 expect(menu.shownItem(0).active()).toBe(true);
790 expect(liElements[1].innerHTML).toEqual("Part-of-Speech");
791 expect(menu.shownItem(1).active()).toBe(false);
792 expect(liElements[2].innerHTML).toEqual("Syntax");
793 expect(menu.shownItem(2).active()).toBe(false);
794 expect(liElements[3]).toBe(undefined);
795 expect(menu.container().items[0].active()).toBe(false);
796 expect(menu.container().items[1].active()).toBe(false);
797 expect(menu.container().items[2].active()).toBe(false); //prefix
798
799 // Activate prev (6)
800 menu.prev();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200801 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200802 expect(liElements[0].innerHTML).toEqual("Lemma");
803 expect(menu.shownItem(0).active()).toBe(true);
804 expect(liElements[1].innerHTML).toEqual("Morphology");
805 expect(menu.shownItem(1).active()).toBe(false);
806 expect(liElements[2].innerHTML).toEqual("Part-of-Speech");
807 expect(menu.shownItem(2).active()).toBe(false);
808 expect(liElements[3]).toBe(undefined);
809 expect(menu.container().items[0].active()).toBe(false);
810 expect(menu.container().items[1].active()).toBe(false);
811 expect(menu.container().items[2].active()).toBe(false); //prefix
812
813 // Activate prev (7)
814 menu.prev();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200815 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200816 expect(liElements[0].innerHTML).toEqual("Constituency");
817 expect(menu.shownItem(0).active()).toBe(true);
818 expect(liElements[1].innerHTML).toEqual("Lemma");
819 expect(menu.shownItem(1).active()).toBe(false);
820 expect(liElements[2].innerHTML).toEqual("Morphology");
821 expect(menu.shownItem(2).active()).toBe(false);
822 expect(liElements[3]).toBe(undefined);
823 expect(menu.container().items[0].active()).toBe(false);
824 expect(menu.container().items[1].active()).toBe(false);
825 expect(menu.container().items[2].active()).toBe(false); //prefix
826
827 // Activate next (8)
828 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200829 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200830 expect(liElements[0].innerHTML).toEqual("Constituency");
831 expect(menu.shownItem(0).active()).toBe(false);
832 expect(liElements[1].innerHTML).toEqual("Lemma");
833 expect(menu.shownItem(1).active()).toBe(true);
834 expect(liElements[2].innerHTML).toEqual("Morphology");
835 expect(menu.shownItem(2).active()).toBe(false);
836 expect(liElements[3]).toBe(undefined);
837 expect(menu.container().items[0].active()).toBe(false);
838 expect(menu.container().items[1].active()).toBe(false);
839 expect(menu.container().items[2].active()).toBe(false); //prefix
840
841 // Activate prev (9)
842 menu.prev();
843 menu.prev();
844 menu.prev();
845
846 // Activate prev (10)
847 menu.prev();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200848 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200849 expect(liElements[0].innerHTML).toEqual("Morphology");
850 expect(menu.shownItem(0).active()).toBe(false);
851 expect(liElements[1].innerHTML).toEqual("Part-of-Speech");
852 expect(menu.shownItem(1).active()).toBe(false);
853 expect(liElements[2].innerHTML).toEqual("Syntax");
854 expect(menu.shownItem(2).active()).toBe(true);
855 expect(liElements[3]).toBe(undefined);
856 expect(menu.container().items[0].active()).toBe(false);
857 expect(menu.container().items[1].active()).toBe(false);
858 expect(menu.container().items[2].active()).toBe(false); //prefix
859 });
860
861 it('should be prevable without active field', function () {
862 var menu = OwnContainerMenu.create(list);
863 menu.limit(3);
864 expect(menu.show()).toBe(true);
865 menu.prev();
866 expect(menu.shownItem(2).active()).toEqual(true);
867 expect(menu.shownItem(2).lcField()).toEqual(' syntax');
868 });
869
870 it('should be navigatable and filterable (prefix = "o")', function () {
871 var menu = OwnContainerMenu.create(list);
872 menu._firstActive = true;
873 menu.limit(2);
874
875 expect(menu.prefix("o").show()).toBe(true);
Leo Reppdedcf1a2021-08-18 18:57:47 +0200876 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200877 expect(liElements[0].innerHTML).toEqual("C<mark>o</mark>nstituency");
878 expect(menu.shownItem(0).active()).toBe(true);
879 expect(liElements[1].innerHTML).toEqual("M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy");
880 expect(menu.shownItem(1).active()).toBe(false);
881 expect(menu.shownItem(2)).toBe(undefined);
882
883 // Next (1)
884 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200885 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200886 expect(liElements[0].innerHTML).toEqual("C<mark>o</mark>nstituency");
887 expect(menu.shownItem(0).active()).toBe(false);
888 expect(liElements[1].innerHTML).toEqual("M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy");
889 expect(menu.shownItem(1).active()).toBe(true);
890 expect(menu.shownItem(2)).toBe(undefined);
891
892 // Next (2)
893 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200894 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200895 expect(liElements[0].innerHTML).toEqual("M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy");
896 expect(menu.shownItem(0).active()).toBe(false);
897 expect(liElements[1].innerHTML).toEqual("Part-<mark>o</mark>f-Speech");
898 expect(menu.shownItem(1).active()).toBe(true);
899 expect(menu.shownItem(2)).toBe(undefined);
900
901 // Next (3) - to prefix
902 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200903 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200904 expect(liElements[0].innerHTML).toEqual("M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy");
905 expect(menu.shownItem(0).active()).toBe(false);
906 expect(liElements[1].innerHTML).toEqual("Part-<mark>o</mark>f-Speech");
907 expect(menu.shownItem(1).active()).toBe(false);
908 expect(menu.shownItem(2)).toBe(undefined);
909
910 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200911 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200912 expect(liElements[0].innerHTML).toEqual("C<mark>o</mark>nstituency");
913 expect(menu.shownItem(0).active()).toBe(true);
914 expect(liElements[1].innerHTML).toEqual("M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy");
915 expect(menu.shownItem(1).active()).toBe(false);
916 expect(menu.shownItem(2)).toBe(undefined);
917 });
918
919 it('should be navigatable and filterable (prefix = "o") using containerItems', function () {
920 var menu = OwnContainerMenu.create(list,ExampleItemList);
921 menu._firstActive = true;
922 menu.limit(2);
923
924 expect(menu.prefix("o").show()).toBe(true);
Leo Reppdedcf1a2021-08-18 18:57:47 +0200925 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200926 expect(liElements[0].innerHTML).toEqual("C<mark>o</mark>nstituency");
927 expect(menu.shownItem(0).active()).toBe(true);
928 expect(liElements[1].innerHTML).toEqual("M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy");
929 expect(menu.shownItem(1).active()).toBe(false);
930 expect(menu.shownItem(2)).toBe(undefined);
931 expect(menu.container().items[0].active()).toBe(false);
932 expect(menu.container().items[1].active()).toBe(false);
933 expect(menu.container().items[2].active()).toBe(false); //prefix
934
935 // Next (1)
936 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200937 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200938 expect(liElements[0].innerHTML).toEqual("C<mark>o</mark>nstituency");
939 expect(menu.shownItem(0).active()).toBe(false);
940 expect(liElements[1].innerHTML).toEqual("M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy");
941 expect(menu.shownItem(1).active()).toBe(true);
942 expect(menu.shownItem(2)).toBe(undefined);
943 expect(menu.container().items[0].active()).toBe(false);
944 expect(menu.container().items[1].active()).toBe(false);
945 expect(menu.container().items[2].active()).toBe(false); //prefix
946
947 // Next (2)
948 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200949 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200950 expect(liElements[0].innerHTML).toEqual("M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy");
951 expect(menu.shownItem(0).active()).toBe(false);
952 expect(liElements[1].innerHTML).toEqual("Part-<mark>o</mark>f-Speech");
953 expect(menu.shownItem(1).active()).toBe(true);
954 expect(menu.shownItem(2)).toBe(undefined);
955 expect(menu.container().items[0].active()).toBe(false);
956 expect(menu.container().items[1].active()).toBe(false);
957 expect(menu.container().items[2].active()).toBe(false); //prefix
958
959 // Next (3) - to first container Item
960 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200961 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200962 expect(liElements[0].innerHTML).toEqual("M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy");
963 expect(menu.shownItem(0).active()).toBe(false);
964 expect(liElements[1].innerHTML).toEqual("Part-<mark>o</mark>f-Speech");
965 expect(menu.shownItem(1).active()).toBe(false);
966 expect(menu.shownItem(2)).toBe(undefined);
967 expect(menu.container().items[0].active()).toBe(true);
968 expect(menu.container().items[1].active()).toBe(false);
969 expect(menu.container().items[2].active()).toBe(false); //prefix
970
971 // Next (4) - to second container Item
972 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200973 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200974 expect(liElements[0].innerHTML).toEqual("M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy");
975 expect(menu.shownItem(0).active()).toBe(false);
976 expect(liElements[1].innerHTML).toEqual("Part-<mark>o</mark>f-Speech");
977 expect(menu.shownItem(1).active()).toBe(false);
978 expect(menu.shownItem(2)).toBe(undefined);
979 expect(menu.container().items[0].active()).toBe(false);
980 expect(menu.container().items[1].active()).toBe(true);
981 expect(menu.container().items[2].active()).toBe(false); //prefix
982
983 // Next (5) - to prefix
984 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200985 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200986 expect(liElements[0].innerHTML).toEqual("M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy");
987 expect(menu.shownItem(0).active()).toBe(false);
988 expect(liElements[1].innerHTML).toEqual("Part-<mark>o</mark>f-Speech");
989 expect(menu.shownItem(1).active()).toBe(false);
990 expect(menu.shownItem(2)).toBe(undefined);
991 expect(menu.container().items[0].active()).toBe(false);
992 expect(menu.container().items[1].active()).toBe(false);
993 expect(menu.container().items[2].active()).toBe(true); //prefix
994
995 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +0200996 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +0200997 expect(liElements[0].innerHTML).toEqual("C<mark>o</mark>nstituency");
998 expect(menu.shownItem(0).active()).toBe(true);
999 expect(liElements[1].innerHTML).toEqual("M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy");
1000 expect(menu.shownItem(1).active()).toBe(false);
1001 expect(menu.shownItem(2)).toBe(undefined);
1002 expect(menu.container().items[0].active()).toBe(false);
1003 expect(menu.container().items[1].active()).toBe(false);
1004 expect(menu.container().items[2].active()).toBe(false); //prefix
1005 });
1006
1007 it('should be navigatable and filterable (prefix = "ex", "e") with containerItems', function () {
1008 var menu = OwnContainerMenu.create(listWithEX,ExampleItemList);
1009 menu._firstActive = true;
1010 menu.limit(3);
1011
1012 expect(menu.prefix("ex").show()).toBe(true);
1013 expect(menu.prefix()).toEqual('ex');
Leo Reppdedcf1a2021-08-18 18:57:47 +02001014 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001015 expect(liElements[0].innerHTML).toEqual("<mark>ex</mark>ample 1 Constituency");
1016 expect(menu.shownItem(0).active()).toBe(true);
1017 expect(liElements[1].innerHTML).toEqual("<mark>ex</mark>ample 2 Morphology");
1018 expect(menu.shownItem(1).active()).toBe(false);
1019 expect(menu.shownItem(3)).toBe(undefined);
1020 expect(menu.container().items[0].active()).toBe(false);
1021 expect(menu.container().items[1].active()).toBe(false);
1022 expect(menu.container().items[2].active()).toBe(false); //prefix
1023
1024 // Next (1)
1025 menu.next();
1026 expect(menu.prefix()).toEqual('ex');
Leo Reppdedcf1a2021-08-18 18:57:47 +02001027 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001028 expect(liElements[0].innerHTML).toEqual("<mark>ex</mark>ample 1 Constituency");
1029 expect(menu.shownItem(0).active()).toBe(false);
1030 expect(liElements[1].innerHTML).toEqual("<mark>ex</mark>ample 2 Morphology");
1031 expect(menu.shownItem(1).active()).toBe(true);
1032 expect(menu.shownItem(3)).toBe(undefined);
1033 expect(menu.container().items[0].active()).toBe(false);
1034 expect(menu.container().items[1].active()).toBe(false);
1035 expect(menu.container().items[2].active()).toBe(false); //prefix
1036
1037 // Next (2)
1038 menu.next();
1039 expect(menu.prefix()).toEqual('ex');
Leo Reppdedcf1a2021-08-18 18:57:47 +02001040 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001041 expect(liElements[0].innerHTML).toEqual("<mark>ex</mark>ample 1 Constituency");
1042 expect(menu.shownItem(0).active()).toBe(false);
1043 expect(liElements[1].innerHTML).toEqual("<mark>ex</mark>ample 2 Morphology");
1044 expect(menu.shownItem(1).active()).toBe(false);
1045 expect(menu.shownItem(3)).toBe(undefined);
1046 expect(menu.container().items[0].active()).toBe(true);
1047 expect(menu.container().items[1].active()).toBe(false);
1048 expect(menu.container().items[2].active()).toBe(false); //prefix
1049
1050 //Roll to Prefix
1051 menu.next();
1052 menu.next();
1053 expect(menu.prefix()).toEqual('ex');
Leo Reppdedcf1a2021-08-18 18:57:47 +02001054 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001055 expect(liElements[0].innerHTML).toEqual("<mark>ex</mark>ample 1 Constituency");
1056 expect(menu.shownItem(0).active()).toBe(false);
1057 expect(liElements[1].innerHTML).toEqual("<mark>ex</mark>ample 2 Morphology");
1058 expect(menu.shownItem(1).active()).toBe(false);
1059 expect(menu.shownItem(3)).toBe(undefined);
1060 expect(menu.container().items[0].active()).toBe(false);
1061 expect(menu.container().items[1].active()).toBe(false);
1062 expect(menu.container().items[2].active()).toBe(true); //prefix
1063
1064 // Reset limit
1065 menu.limit(5);
1066
1067 // Change show
1068 expect(menu.prefix("e").show()).toBe(true);
1069 expect(menu._prefix.active()).toBe(false);
1070 expect(menu.prefix()).toEqual('e');
Leo Reppdedcf1a2021-08-18 18:57:47 +02001071 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001072 expect(liElements[0].innerHTML).toEqual("<mark>e</mark>xampl<mark>e</mark> 1 Constitu<mark>e</mark>ncy");
1073 expect(menu.shownItem(0).active()).toBe(true);
1074 expect(liElements[1].innerHTML).toEqual("<mark>e</mark>xampl<mark>e</mark> 2 Morphology");
1075 expect(menu.shownItem(1).active()).toBe(false);
1076 expect(menu.shownItem(3)).toBe(undefined);
1077 expect(menu.container().items[0].active()).toBe(false);
1078 expect(menu.container().items[1].active()).toBe(false);
1079 expect(menu.container().items[2].active()).toBe(false); //prefix
1080
1081 // Next (1)
1082 menu.next();
1083 expect(menu._prefix.active()).toBe(false);
1084 expect(menu.prefix()).toEqual('e');
Leo Reppdedcf1a2021-08-18 18:57:47 +02001085 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001086 expect(liElements[0].innerHTML).toEqual("<mark>e</mark>xampl<mark>e</mark> 1 Constitu<mark>e</mark>ncy");
1087 expect(menu.shownItem(0).active()).toBe(false);
1088 expect(liElements[1].innerHTML).toEqual("<mark>e</mark>xampl<mark>e</mark> 2 Morphology");
1089 expect(menu.shownItem(1).active()).toBe(true);
1090 expect(menu.shownItem(3)).toBe(undefined);
1091 expect(menu.container().items[0].active()).toBe(false);
1092 expect(menu.container().items[1].active()).toBe(false);
1093 expect(menu.container().items[2].active()).toBe(false); //prefix
1094
1095 // Next (2)
1096 menu.next();
1097 expect(menu._prefix.active()).toBe(false);
1098 expect(menu.prefix()).toEqual('e');
Leo Reppdedcf1a2021-08-18 18:57:47 +02001099 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001100 expect(liElements[0].innerHTML).toEqual("<mark>e</mark>xampl<mark>e</mark> 1 Constitu<mark>e</mark>ncy");
1101 expect(menu.shownItem(0).active()).toBe(false);
1102 expect(liElements[1].innerHTML).toEqual("<mark>e</mark>xampl<mark>e</mark> 2 Morphology");
1103 expect(menu.shownItem(1).active()).toBe(false);
1104 expect(menu.shownItem(3)).toBe(undefined);
1105 expect(menu.container().items[0].active()).toBe(true);
1106 expect(menu.container().items[1].active()).toBe(false);
1107 expect(menu.container().items[2].active()).toBe(false); //prefix
1108
1109
1110 // Next (3)
1111 menu.next();
1112 menu.next();
1113 expect(menu._prefix.active()).toBe(true);
1114 expect(menu.prefix()).toEqual('e');
Leo Reppdedcf1a2021-08-18 18:57:47 +02001115 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001116 expect(liElements[0].innerHTML).toEqual("<mark>e</mark>xampl<mark>e</mark> 1 Constitu<mark>e</mark>ncy");
1117 expect(menu.shownItem(0).active()).toBe(false);
1118 expect(liElements[1].innerHTML).toEqual("<mark>e</mark>xampl<mark>e</mark> 2 Morphology");
1119 expect(menu.shownItem(1).active()).toBe(false);
1120 expect(menu.shownItem(3)).toBe(undefined);
1121 expect(menu.container().items[0].active()).toBe(false);
1122 expect(menu.container().items[1].active()).toBe(false);
1123 expect(menu.container().items[2].active()).toBe(true); //prefix
1124 });
1125
1126
1127 it('should be filterable (multiple prefix = "pro sin")', function () {
1128 var menu = OwnContainerMenu.create(listMultiPrefix);
1129 menu._firstActive = true;
1130
1131 menu.limit(2);
1132 expect(menu.prefix("pro sin").show()).toBe(true);
Leo Reppdedcf1a2021-08-18 18:57:47 +02001133 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001134 expect(liElements[0].innerHTML).toEqual(
1135 "Personal <mark>Pro</mark>noun, <mark>Sin</mark>gular"
1136 );
1137
1138 expect(menu.shownItem(0).active()).toBe(true);
1139 expect(liElements[1].innerHTML).toEqual("Personal <mark>Pro</mark>noun, <mark>Sin</mark>gular, Accusative");
1140 expect(menu.shownItem(1).active()).toBe(false);
1141
1142 expect(menu.shownItem(2)).toBe(undefined);
1143 });
1144
1145 it('should be filterable (trimming = " p")', function () {
1146 var menu = OwnContainerMenu.create(listMultiPrefix);
1147 // menu._firstActive = true;
1148
1149 menu.limit(2);
1150 expect(menu.show()).toBe(true);
1151 menu._prefix.add(" ");
1152 expect(menu.show()).toBe(true);
1153 menu._prefix.add("p")
1154 expect(menu.show()).toBe(true);
Leo Reppdedcf1a2021-08-18 18:57:47 +02001155 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001156 expect(liElements[0].innerHTML).toEqual("<mark>P</mark>ersonal <mark>P</mark>ronoun");
1157 });
1158
1159
1160 it('should choose prefix with failing prefix (1)', function () {
1161 var menu = OwnContainerMenu.create(list);
1162 menu.limit(2);
1163 expect(menu.prefix("exit").show()).toBe(true);
1164 expect(menu.element().querySelector('li')).toBe(null);
1165 expect(menu.shownItem(0)).toBeUndefined();
1166 expect(menu._prefix.active()).toBe(true);
1167 });
1168
1169
1170 it('should choose prefix with failing prefix (2)', function () {
1171 var menu = OwnContainerMenu.create(list);
1172 menu.limit(2);
1173 expect(menu.show()).toBe(true);
1174 expect(menu.prefix("exit").show()).toBe(true);
1175 expect(menu.element().querySelector('li')).toBe(null);
1176 expect(menu.shownItem(0)).toBeUndefined();
1177 expect(menu._prefix.active()).toBe(true);
1178 });
1179
1180 it('should ignore navigation with failing prefix', function () {
1181 var menu = OwnContainerMenu.create(list);
1182 menu.limit(2);
1183 expect(menu.show()).toBe(true);
1184
1185 menu.next();
1186
1187 expect(menu.prefix("exit").show()).toBe(true);
1188 expect(menu.element().querySelector('li')).toBe(null);
1189 expect(menu.shownItem(0)).toBeUndefined();
1190 expect(menu._prefix.active()).toBe(true);
1191
1192 menu.next();
1193 expect(menu._prefix.active()).toBe(true);
1194
1195 menu.prev();
1196 expect(menu._prefix.active()).toBe(true);
1197
1198 });
1199
1200 it('should be navigatable with prefix', function () {
1201 var menu = OwnContainerMenu.create(demolist);
1202 menu._firstActive = true;
1203
1204 menu.limit(3);
1205
1206 expect(menu.show()).toBe(true);
1207 expect(menu.prefix()).toEqual("");
1208
Leo Reppdedcf1a2021-08-18 18:57:47 +02001209 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001210 expect(liElements[0].innerHTML).toEqual("Titel");
1211 expect(menu.shownItem(0).active()).toBe(true);
1212 expect(liElements[1].innerHTML).toEqual("Untertitel");
1213 expect(menu.shownItem(1).active()).toBe(false);
1214 expect(liElements[2].innerHTML).toEqual("Veröffentlichungsdatum");
1215 expect(menu.shownItem(2).active()).toBe(false);
1216 expect(menu.shownItem(3)).toBe(undefined);
1217
1218 menu._prefix.add('a');
1219 expect(menu.show()).toBe(true);
1220 expect(menu.prefix()).toEqual("a");
Leo Reppdedcf1a2021-08-18 18:57:47 +02001221 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001222 expect(liElements[0].innerHTML).toEqual("<mark>A</mark>utor");
1223
1224 menu._prefix.add('u');
1225 expect(menu.show()).toBe(true);
1226 expect(menu.prefix()).toEqual("au");
Leo Reppdedcf1a2021-08-18 18:57:47 +02001227 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001228 expect(liElements[0].innerHTML).toEqual("<mark>Au</mark>tor");
1229
1230 menu._prefix.chop();
1231 expect(menu.show()).toBe(true);
1232 expect(menu.prefix()).toEqual("a");
Leo Reppdedcf1a2021-08-18 18:57:47 +02001233 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001234 expect(liElements[0].innerHTML).toEqual("<mark>A</mark>utor");
1235
1236 menu._prefix.chop();
1237 expect(menu.show()).toBe(true);
1238 expect(menu.prefix()).toEqual("");
Leo Reppdedcf1a2021-08-18 18:57:47 +02001239 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001240 expect(liElements[0].innerHTML).toEqual("Titel");
1241 expect(menu.shownItem(0).active()).toBe(true);
1242 expect(liElements[1].innerHTML).toEqual("Untertitel");
1243 expect(menu.shownItem(1).active()).toBe(false);
1244 expect(liElements[2].innerHTML).toEqual("Veröffentlichungsdatum");
1245 expect(menu.shownItem(2).active()).toBe(false);
1246 expect(menu.shownItem(3)).toBe(undefined);
1247
1248 // Forward
1249 menu._prefix.chop();
1250 expect(menu.show()).toBe(true);
1251 expect(menu.prefix()).toEqual("");
Leo Reppdedcf1a2021-08-18 18:57:47 +02001252 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001253 expect(liElements[0].innerHTML).toEqual("Titel");
1254 expect(menu.shownItem(0).active()).toBe(true);
1255 expect(liElements[1].innerHTML).toEqual("Untertitel");
1256 expect(menu.shownItem(1).active()).toBe(false);
1257 expect(liElements[2].innerHTML).toEqual("Veröffentlichungsdatum");
1258 expect(menu.shownItem(2).active()).toBe(false);
1259
1260 // Forward
1261 menu.next();
1262 expect(menu.prefix()).toEqual("");
Leo Reppdedcf1a2021-08-18 18:57:47 +02001263 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001264 expect(liElements[0].innerHTML).toEqual("Titel");
1265 expect(menu.shownItem(0).active()).toBe(false);
1266 expect(liElements[1].innerHTML).toEqual("Untertitel");
1267 expect(menu.shownItem(1).active()).toBe(true);
1268 expect(liElements[2].innerHTML).toEqual("Veröffentlichungsdatum");
1269 expect(menu.shownItem(2).active()).toBe(false);
1270 expect(menu.shownItem(3)).toBe(undefined);
1271
1272 // Forward
1273 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +02001274 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001275 expect(menu.prefix()).toEqual("");
1276 expect(liElements[0].innerHTML).toEqual("Titel");
1277 expect(menu.shownItem(0).active()).toBe(false);
1278 expect(liElements[1].innerHTML).toEqual("Untertitel");
1279 expect(menu.shownItem(1).active()).toBe(false);
1280 expect(liElements[2].innerHTML).toEqual("Veröffentlichungsdatum");
1281 expect(menu.shownItem(2).active()).toBe(true);
1282 expect(menu.shownItem(3)).toBe(undefined);
1283
1284 // Forward
1285 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +02001286 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001287 expect(menu.prefix()).toEqual("");
1288 expect(liElements[0].innerHTML).toEqual("Untertitel");
1289 expect(menu.shownItem(0).active()).toBe(false);
1290 expect(liElements[1].innerHTML).toEqual("Veröffentlichungsdatum");
1291 expect(menu.shownItem(1).active()).toBe(false);
1292 expect(liElements[2].innerHTML).toEqual("Länge");
1293 expect(menu.shownItem(2).active()).toBe(true);
1294 expect(menu.shownItem(3)).toBe(undefined);
1295
1296 // Forward
1297 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +02001298 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001299 expect(menu.prefix()).toEqual("");
1300 expect(liElements[0].innerHTML).toEqual("Veröffentlichungsdatum");
1301 expect(menu.shownItem(0).active()).toBe(false);
1302 expect(liElements[1].innerHTML).toEqual("Länge");
1303 expect(menu.shownItem(1).active()).toBe(false);
1304 expect(liElements[2].innerHTML).toEqual("Autor");
1305 expect(menu.shownItem(2).active()).toBe(true);
1306 expect(menu.shownItem(3)).toBe(undefined);
1307
1308 // Forward
1309 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +02001310 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001311 expect(menu.prefix()).toEqual("");
1312 expect(liElements[0].innerHTML).toEqual("Titel");
1313 expect(menu.shownItem(0).active()).toBe(true);
1314 expect(liElements[1].innerHTML).toEqual("Untertitel");
1315 expect(menu.shownItem(1).active()).toBe(false);
1316 expect(liElements[2].innerHTML).toEqual("Veröffentlichungsdatum");
1317 expect(menu.shownItem(2).active()).toBe(false);
1318 });
1319
1320 it('should be navigatable with prefix and containerItems', function () {
1321 var menu = OwnContainerMenu.create(demolist,ExampleItemList);
1322 menu._firstActive = true;
1323
1324 menu.limit(3);
1325
1326 expect(menu.show()).toBe(true);
1327 expect(menu.prefix()).toEqual("");
1328
Leo Reppdedcf1a2021-08-18 18:57:47 +02001329 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001330 expect(liElements[0].innerHTML).toEqual("Titel");
1331 expect(menu.shownItem(0).active()).toBe(true);
1332 expect(liElements[1].innerHTML).toEqual("Untertitel");
1333 expect(menu.shownItem(1).active()).toBe(false);
1334 expect(liElements[2].innerHTML).toEqual("Veröffentlichungsdatum");
1335 expect(menu.shownItem(2).active()).toBe(false);
1336 expect(menu.shownItem(3)).toBe(undefined);
1337 expect(menu.container().items[0].active()).toBe(false);
1338 expect(menu.container().items[1].active()).toBe(false);
1339 expect(menu.container().items[2].active()).toBe(false); //prefix
1340
1341 menu._prefix.add('a');
1342 expect(menu.show()).toBe(true);
1343 expect(menu.prefix()).toEqual("a");
Leo Reppdedcf1a2021-08-18 18:57:47 +02001344 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001345 expect(liElements[0].innerHTML).toEqual("<mark>A</mark>utor");
1346 expect(menu.container().items[0].active()).toBe(false);
1347 expect(menu.container().items[1].active()).toBe(false);
1348 expect(menu.container().items[2].active()).toBe(false); //prefix
1349
1350 menu._prefix.add('u');
1351 expect(menu.show()).toBe(true);
1352 expect(menu.prefix()).toEqual("au");
Leo Reppdedcf1a2021-08-18 18:57:47 +02001353 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001354 expect(liElements[0].innerHTML).toEqual("<mark>Au</mark>tor");
1355 expect(menu.container().items[0].active()).toBe(false);
1356 expect(menu.container().items[1].active()).toBe(false);
1357 expect(menu.container().items[2].active()).toBe(false); //prefix
1358
1359 menu._prefix.chop();
1360 expect(menu.show()).toBe(true);
1361 expect(menu.prefix()).toEqual("a");
Leo Reppdedcf1a2021-08-18 18:57:47 +02001362 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001363 expect(liElements[0].innerHTML).toEqual("<mark>A</mark>utor");
1364 expect(menu.container().items[0].active()).toBe(false);
1365 expect(menu.container().items[1].active()).toBe(false);
1366 expect(menu.container().items[2].active()).toBe(false); //prefix
1367
1368 menu._prefix.chop();
1369 expect(menu.show()).toBe(true);
1370 expect(menu.prefix()).toEqual("");
Leo Reppdedcf1a2021-08-18 18:57:47 +02001371 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001372 expect(liElements[0].innerHTML).toEqual("Titel");
1373 expect(menu.shownItem(0).active()).toBe(true);
1374 expect(liElements[1].innerHTML).toEqual("Untertitel");
1375 expect(menu.shownItem(1).active()).toBe(false);
1376 expect(liElements[2].innerHTML).toEqual("Veröffentlichungsdatum");
1377 expect(menu.shownItem(2).active()).toBe(false);
1378 expect(menu.shownItem(3)).toBe(undefined);
1379 expect(menu.container().items[0].active()).toBe(false);
1380 expect(menu.container().items[1].active()).toBe(false);
1381 expect(menu.container().items[2].active()).toBe(false); //prefix
1382
1383 // Forward
1384 menu._prefix.chop();
1385 expect(menu.show()).toBe(true);
1386 expect(menu.prefix()).toEqual("");
Leo Reppdedcf1a2021-08-18 18:57:47 +02001387 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001388 expect(liElements[0].innerHTML).toEqual("Titel");
1389 expect(menu.shownItem(0).active()).toBe(true);
1390 expect(liElements[1].innerHTML).toEqual("Untertitel");
1391 expect(menu.shownItem(1).active()).toBe(false);
1392 expect(liElements[2].innerHTML).toEqual("Veröffentlichungsdatum");
1393 expect(menu.shownItem(2).active()).toBe(false);
1394 expect(menu.container().items[0].active()).toBe(false);
1395 expect(menu.container().items[1].active()).toBe(false);
1396 expect(menu.container().items[2].active()).toBe(false); //prefix
1397
1398 // Forward
1399 menu.next();
1400 expect(menu.prefix()).toEqual("");
Leo Reppdedcf1a2021-08-18 18:57:47 +02001401 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001402 expect(liElements[0].innerHTML).toEqual("Titel");
1403 expect(menu.shownItem(0).active()).toBe(false);
1404 expect(liElements[1].innerHTML).toEqual("Untertitel");
1405 expect(menu.shownItem(1).active()).toBe(true);
1406 expect(liElements[2].innerHTML).toEqual("Veröffentlichungsdatum");
1407 expect(menu.shownItem(2).active()).toBe(false);
1408 expect(menu.shownItem(3)).toBe(undefined);
1409 expect(menu.container().items[0].active()).toBe(false);
1410 expect(menu.container().items[1].active()).toBe(false);
1411 expect(menu.container().items[2].active()).toBe(false); //prefix
1412
1413 // Forward
1414 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +02001415 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001416 expect(menu.prefix()).toEqual("");
1417 expect(liElements[0].innerHTML).toEqual("Titel");
1418 expect(menu.shownItem(0).active()).toBe(false);
1419 expect(liElements[1].innerHTML).toEqual("Untertitel");
1420 expect(menu.shownItem(1).active()).toBe(false);
1421 expect(liElements[2].innerHTML).toEqual("Veröffentlichungsdatum");
1422 expect(menu.shownItem(2).active()).toBe(true);
1423 expect(menu.shownItem(3)).toBe(undefined);
1424 expect(menu.container().items[0].active()).toBe(false);
1425 expect(menu.container().items[1].active()).toBe(false);
1426 expect(menu.container().items[2].active()).toBe(false); //prefix
1427
1428 // Forward
1429 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +02001430 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001431 expect(menu.prefix()).toEqual("");
1432 expect(liElements[0].innerHTML).toEqual("Untertitel");
1433 expect(menu.shownItem(0).active()).toBe(false);
1434 expect(liElements[1].innerHTML).toEqual("Veröffentlichungsdatum");
1435 expect(menu.shownItem(1).active()).toBe(false);
1436 expect(liElements[2].innerHTML).toEqual("Länge");
1437 expect(menu.shownItem(2).active()).toBe(true);
1438 expect(menu.shownItem(3)).toBe(undefined);
1439 expect(menu.container().items[0].active()).toBe(false);
1440 expect(menu.container().items[1].active()).toBe(false);
1441 expect(menu.container().items[2].active()).toBe(false); //prefix
1442
1443 // Forward
1444 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +02001445 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001446 expect(menu.prefix()).toEqual("");
1447 expect(liElements[0].innerHTML).toEqual("Veröffentlichungsdatum");
1448 expect(menu.shownItem(0).active()).toBe(false);
1449 expect(liElements[1].innerHTML).toEqual("Länge");
1450 expect(menu.shownItem(1).active()).toBe(false);
1451 expect(liElements[2].innerHTML).toEqual("Autor");
1452 expect(menu.shownItem(2).active()).toBe(true);
1453 expect(menu.shownItem(3)).toBe(undefined);
1454 expect(menu.container().items[0].active()).toBe(false);
1455 expect(menu.container().items[1].active()).toBe(false);
1456 expect(menu.container().items[2].active()).toBe(false); //prefix
1457
1458 // Forward
1459 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +02001460 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001461 expect(menu.prefix()).toEqual("");
1462 expect(liElements[0].innerHTML).toEqual("Veröffentlichungsdatum");
1463 expect(menu.shownItem(0).active()).toBe(false);
1464 expect(liElements[1].innerHTML).toEqual("Länge");
1465 expect(menu.shownItem(1).active()).toBe(false);
1466 expect(liElements[2].innerHTML).toEqual("Autor");
1467 expect(menu.shownItem(2).active()).toBe(false);
1468 expect(menu.shownItem(3)).toBe(undefined);
1469 expect(menu.container().items[0].active()).toBe(true);
1470 expect(menu.container().items[1].active()).toBe(false);
1471 expect(menu.container().items[2].active()).toBe(false); //prefix
1472
1473 // Forward
1474 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +02001475 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001476 expect(menu.prefix()).toEqual("");
1477 expect(liElements[0].innerHTML).toEqual("Veröffentlichungsdatum");
1478 expect(menu.shownItem(0).active()).toBe(false);
1479 expect(liElements[1].innerHTML).toEqual("Länge");
1480 expect(menu.shownItem(1).active()).toBe(false);
1481 expect(liElements[2].innerHTML).toEqual("Autor");
1482 expect(menu.shownItem(2).active()).toBe(false);
1483 expect(menu.shownItem(3)).toBe(undefined);
1484 expect(menu.container().items[0].active()).toBe(false);
1485 expect(menu.container().items[1].active()).toBe(true);
1486 expect(menu.container().items[2].active()).toBe(false); //prefix
1487
1488 // Forward
1489 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +02001490 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001491 expect(menu.prefix()).toEqual("");
1492 expect(liElements[0].innerHTML).toEqual("Titel");
1493 expect(menu.shownItem(0).active()).toBe(true);
1494 expect(liElements[1].innerHTML).toEqual("Untertitel");
1495 expect(menu.shownItem(1).active()).toBe(false);
1496 expect(liElements[2].innerHTML).toEqual("Veröffentlichungsdatum");
1497 expect(menu.shownItem(2).active()).toBe(false);
1498 expect(menu.container().items[0].active()).toBe(false);
1499 expect(menu.container().items[1].active()).toBe(false);
1500 expect(menu.container().items[2].active()).toBe(false); //prefix
1501 });
1502
1503 it('should be navigatable with a prefix (1) and containerItems', function () {
1504 var menu = OwnContainerMenu.create(demolist, ExampleItemList);
1505 menu._firstActive = true;
1506
1507 menu.limit(3);
1508
1509 expect(menu.show()).toBe(true);
1510 expect(menu.prefix()).toEqual("");
1511
1512 // Add prefix in uppercase - but check in lowercase
1513 menu.prefix('El');
1514 expect(menu.show()).toBe(true);
1515
Leo Reppdedcf1a2021-08-18 18:57:47 +02001516 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001517 expect(menu.prefix()).toEqual("El");
1518 expect(menu._prefix.active()).toEqual(false);
1519 expect(liElements[0].innerHTML).toEqual("Tit<mark>el</mark>");
1520 expect(menu.shownItem(0).active()).toBe(true);
1521 expect(liElements[1].innerHTML).toEqual("Untertit<mark>el</mark>");
1522 expect(menu.shownItem(1).active()).toBe(false);
1523 expect(menu.shownItem(2)).toBe(undefined);
1524 expect(menu.container().items[0].active()).toBe(false);
1525 expect(menu.container().items[1].active()).toBe(false);
1526 expect(menu.container().items[2].active()).toBe(false); //prefix
1527
1528 // Forward
1529 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +02001530 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001531 expect(menu.prefix()).toEqual("El");
1532 expect(menu._prefix.active()).toEqual(false);
1533 expect(liElements[0].innerHTML).toEqual("Tit<mark>el</mark>");
1534 expect(menu.shownItem(0).active()).toBe(false);
1535 expect(liElements[1].innerHTML).toEqual("Untertit<mark>el</mark>");
1536 expect(menu.shownItem(1).active()).toBe(true);
1537 expect(menu.shownItem(2)).toBe(undefined);
1538 expect(menu.container().items[0].active()).toBe(false);
1539 expect(menu.container().items[1].active()).toBe(false);
1540 expect(menu.container().items[2].active()).toBe(false); //prefix
1541
1542 // Forward
1543 menu.next();
Leo Reppdedcf1a2021-08-18 18:57:47 +02001544 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001545 expect(menu.prefix()).toEqual("El");
1546 expect(liElements[0].innerHTML).toEqual("Tit<mark>el</mark>");
1547 expect(menu.shownItem(0).active()).toBe(false);
1548 expect(liElements[1].innerHTML).toEqual("Untertit<mark>el</mark>");
1549 expect(menu.shownItem(1).active()).toBe(false);
1550 expect(menu.shownItem(2)).toBe(undefined);
1551 expect(menu.container().items[0].active()).toBe(true);
1552 expect(menu.container().items[1].active()).toBe(false);
1553 expect(menu.container().items[2].active()).toBe(false); //prefix
1554
1555 menu.next();
1556 menu.next();
1557
Leo Reppdedcf1a2021-08-18 18:57:47 +02001558 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001559 expect(menu.prefix()).toEqual("El");
1560 expect(liElements[0].innerHTML).toEqual("Tit<mark>el</mark>");
1561 expect(menu.shownItem(0).active()).toBe(false);
1562 expect(liElements[1].innerHTML).toEqual("Untertit<mark>el</mark>");
1563 expect(menu.shownItem(1).active()).toBe(false);
1564 expect(menu.shownItem(2)).toBe(undefined);
1565 expect(menu.container().items[0].active()).toBe(false);
1566 expect(menu.container().items[1].active()).toBe(false);
1567 expect(menu.container().items[2].active()).toBe(true); //prefix
1568
1569 // Backward
1570 menu.prev();
1571 menu.prev();
1572 menu.prev();
Leo Reppdedcf1a2021-08-18 18:57:47 +02001573 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001574 expect(menu.prefix()).toEqual("El");
1575 expect(menu._prefix.active()).toEqual(false);
1576 expect(liElements[0].innerHTML).toEqual("Tit<mark>el</mark>");
1577 expect(menu.shownItem(0).active()).toBe(false);
1578 expect(liElements[1].innerHTML).toEqual("Untertit<mark>el</mark>");
1579 expect(menu.shownItem(1).active()).toBe(true);
1580 expect(menu.shownItem(2)).toBe(undefined);
1581 expect(menu.container().items[0].active()).toBe(false);
1582 expect(menu.container().items[1].active()).toBe(false);
1583 expect(menu.container().items[2].active()).toBe(false); //prefix
1584 });
1585
1586
1587 it('should be navigatable with a prefix (2) and containerItems', function () {
1588 var menu = OwnContainerMenu.create(demolist,ExampleItemList);
1589 menu._firstActive = true;
1590
1591 menu.limit(3);
1592 expect(menu.show()).toBe(true);
1593 expect(menu.prefix()).toEqual("");
1594 menu.prefix('el');
1595 expect(menu.show()).toBe(true);
1596
Leo Reppdedcf1a2021-08-18 18:57:47 +02001597 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001598 expect(menu.prefix()).toEqual("el");
1599 expect(menu._prefix.active()).toEqual(false);
1600 expect(liElements[0].innerHTML).toEqual("Tit<mark>el</mark>");
1601 expect(menu.shownItem(0).active()).toBe(true);
1602 expect(liElements[1].innerHTML).toEqual("Untertit<mark>el</mark>");
1603 expect(menu.shownItem(1).active()).toBe(false);
1604 expect(menu.shownItem(2)).toBe(undefined);
1605 expect(menu.container().items[0].active()).toBe(false);
1606 expect(menu.container().items[1].active()).toBe(false);
1607 expect(menu.container().items[2].active()).toBe(false); //prefix
1608
1609 // Backward
1610 menu.prev();
1611 expect(menu._prefix.active()).toEqual(true);
1612
Leo Reppdedcf1a2021-08-18 18:57:47 +02001613 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001614 expect(liElements[0].innerHTML).toEqual("Tit<mark>el</mark>");
1615 expect(menu.shownItem(0).active()).toBe(false);
1616 expect(liElements[1].innerHTML).toEqual("Untertit<mark>el</mark>");
1617 expect(menu.shownItem(1).active()).toBe(false);
1618 expect(menu.shownItem(2)).toBe(undefined);
1619 expect(menu.container().items[0].active()).toBe(false);
1620 expect(menu.container().items[1].active()).toBe(false);
1621 expect(menu.container().items[2].active()).toBe(true); //prefix
1622
1623 // Backward
1624 menu.prev();
1625 menu.prev();
1626 menu.prev();
Leo Reppdedcf1a2021-08-18 18:57:47 +02001627 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001628 expect(menu._prefix.active()).toEqual(false);
1629 expect(liElements[0].innerHTML).toEqual("Tit<mark>el</mark>");
1630 expect(menu.shownItem(0).active()).toBe(false);
1631 expect(liElements[1].innerHTML).toEqual("Untertit<mark>el</mark>");
1632 expect(menu.shownItem(1).active()).toBe(true);
1633 expect(menu.shownItem(2)).toBe(undefined);
1634 expect(menu.container().items[0].active()).toBe(false);
1635 expect(menu.container().items[1].active()).toBe(false);
1636 expect(menu.container().items[2].active()).toBe(false); //prefix
1637 });
1638
1639 it('should be navigatable with a prefix (3) and containerItems', function () {
1640 var menu = OwnContainerMenu.create(demolist,ExampleItemList);
1641 menu._firstActive = true;
1642 menu.limit(3);
1643 expect(menu.show()).toBe(true);
1644 expect(menu.prefix()).toEqual("");
1645 menu.prefix('el');
1646 expect(menu.show()).toBe(true);
1647
Leo Reppdedcf1a2021-08-18 18:57:47 +02001648 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001649 expect(menu.prefix()).toEqual("el");
1650 expect(menu._prefix.active()).toEqual(false);
1651 expect(liElements[0].innerHTML).toEqual("Tit<mark>el</mark>");
1652 expect(menu.shownItem(0).active()).toBe(true);
1653 expect(liElements[1].innerHTML).toEqual("Untertit<mark>el</mark>");
1654 expect(menu.shownItem(1).active()).toBe(false);
1655 expect(menu.shownItem(2)).toBe(undefined);
1656 expect(menu.container().items[0].active()).toBe(false);
1657 expect(menu.container().items[1].active()).toBe(false);
1658 expect(menu.container().items[2].active()).toBe(false); //prefix
1659
1660 // Backward
1661 menu.prev();
Leo Reppdedcf1a2021-08-18 18:57:47 +02001662 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001663 expect(menu._prefix.active()).toEqual(true);
1664 expect(liElements[0].innerHTML).toEqual("Tit<mark>el</mark>");
1665 expect(menu.shownItem(0).active()).toBe(false);
1666 expect(liElements[1].innerHTML).toEqual("Untertit<mark>el</mark>");
1667 expect(menu.shownItem(1).active()).toBe(false);
1668 expect(menu.shownItem(2)).toBe(undefined);
1669 expect(menu.container().items[0].active()).toBe(false);
1670 expect(menu.container().items[1].active()).toBe(false);
1671 expect(menu.container().items[2].active()).toBe(true); //prefix
1672
1673
1674 // Forward
1675 menu.next();
1676 expect(menu.prefix()).toEqual("el");
1677 expect(menu._prefix.active()).toEqual(false);
Leo Reppdedcf1a2021-08-18 18:57:47 +02001678 var liElements = directElementChildrenByTagName(menu.element(),"li");
Leo Reppd162b2e2021-06-30 13:51:07 +02001679 expect(liElements[0].innerHTML).toEqual("Tit<mark>el</mark>");
1680 expect(menu.shownItem(0).active()).toBe(true);
1681 expect(liElements[1].innerHTML).toEqual("Untertit<mark>el</mark>");
1682 expect(menu.shownItem(1).active()).toBe(false);
1683 expect(menu.shownItem(2)).toBe(undefined);
1684 expect(menu.container().items[0].active()).toBe(false);
1685 expect(menu.container().items[1].active()).toBe(false);
1686 expect(menu.container().items[2].active()).toBe(false); //prefix
1687
1688 });
1689
1690 it('should show screens by offset', function () {
1691 var menu = OwnContainerMenu.create(demolist,ExampleItemList);
1692 menu.limit(3);
1693 expect(menu.show()).toBe(true);
1694
1695 expect(menu.shownItem(0).active()).toBe(false);
1696 expect(menu.shownItem(1).active()).toBe(false);
1697 expect(menu.shownItem(2).active()).toBe(false);
1698 expect(menu.container().items[0].active()).toBe(false);
1699 expect(menu.container().items[1].active()).toBe(false);
1700 expect(menu.container().items[2].active()).toBe(false); //prefix
1701
1702 // Highlight the first entry
1703 menu.next();
1704
1705 expect(menu.shownItem(0).active()).toBe(true);
1706 expect(menu.shownItem(1).active()).toBe(false);
1707 expect(menu.shownItem(2).active()).toBe(false);
1708
1709 // Highlight the second entry
1710 menu.next();
1711
1712 expect(menu.shownItem(0).active()).toBe(false);
1713 expect(menu.shownItem(1).active()).toBe(true);
1714 expect(menu.shownItem(2).active()).toBe(false);
1715 expect(menu.shownItem(3)).toBe(undefined);
1716
1717 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1718 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1719
1720 // Move to first screen
1721 menu.screen(0);
1722 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1723 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1724 expect(menu.shownItem(0).active()).toBe(false);
1725 expect(menu.shownItem(1).active()).toBe(true);
1726 expect(menu.shownItem(2).active()).toBe(false);
1727 expect(menu.shownItem(3)).toBe(undefined);
1728
1729 // Move to second screen
1730 menu.screen(1);
1731 expect(menu.shownItem(0).lcField()).toEqual(' untertitel');
1732 expect(menu.shownItem(0).active()).toBe(true);
1733 expect(menu.shownItem(1).active()).toBe(false);
1734 expect(menu.shownItem(2).active()).toBe(false);
1735 expect(menu.shownItem(3)).toBe(undefined);
1736
1737 menu.screen(2);
1738 expect(menu.shownItem(0).lcField()).toEqual(' veröffentlichungsdatum');
1739 expect(menu.shownItem(0).active()).toBe(false);
1740 expect(menu.shownItem(1).active()).toBe(false);
1741 expect(menu.shownItem(2).active()).toBe(false);
1742 expect(menu.shownItem(3)).toBe(undefined);
1743
1744 menu.screen(1);
1745 expect(menu.shownItem(0).lcField()).toEqual(' untertitel');
1746 expect(menu.shownItem(0).active()).toBe(true);
1747 expect(menu.shownItem(1).active()).toBe(false);
1748 expect(menu.shownItem(2).active()).toBe(false);
1749 expect(menu.shownItem(3)).toBe(undefined);
1750 expect(menu.container().items[0].active()).toBe(false);
1751 expect(menu.container().items[1].active()).toBe(false);
1752 expect(menu.container().items[2].active()).toBe(false); //prefix
1753 });
1754
1755 it('should show screens by offset when prefixed', function () {
1756 var menu = OwnContainerMenu.create(demolist,ExampleItemList);
1757 menu.limit(3);
1758 expect(menu.prefix("e").show()).toBe(true);
1759 expect(menu.shownItem(0).active()).toBe(false);
1760 expect(menu.shownItem(1).active()).toBe(false);
1761 expect(menu.shownItem(2).active()).toBe(false);
1762 expect(menu.container().items[0].active()).toBe(false);
1763 expect(menu.container().items[1].active()).toBe(false);
1764 expect(menu.container().items[2].active()).toBe(false); //prefix
1765
1766 expect(menu.shownItem(0).element().innerHTML).toEqual('Tit<mark>e</mark>l');
1767 menu.screen(1);
1768 expect(menu.shownItem(0).element().innerHTML).toEqual('Unt<mark>e</mark>rtit<mark>e</mark>l');
1769 });
1770
1771
1772 it('should be page downable', function () {
1773 var menu = OwnContainerMenu.create(demolonglist,ExampleItemList);
1774 menu.limit(3);
1775
1776 expect(menu.show(0)).toBe(true);
1777
1778 expect(menu.container().items[0].active()).toBe(false);
1779 expect(menu.container().items[1].active()).toBe(false);
1780 expect(menu.container().items[2].active()).toBe(false); //prefix
1781
1782 expect(menu.shownItem(0).active()).toBe(true);
1783 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1784 expect(menu.shownItem(1).active()).toBe(false);
1785 expect(menu.shownItem(2).active()).toBe(false);
1786 expect(menu.shownItem(3)).toBe(undefined);
1787
1788 menu.pageDown();
1789
1790 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1791 expect(menu.shownItem(0).active()).toBe(false);
1792 expect(menu.shownItem(1).active()).toBe(false);
1793 expect(menu.shownItem(2).active()).toBe(false);
1794
1795 menu.pageDown();
1796
1797 expect(menu.shownItem(0).lcField()).toEqual(' corpusid');
1798 expect(menu.shownItem(0).active()).toBe(false);
1799 expect(menu.shownItem(1).active()).toBe(false);
1800 expect(menu.shownItem(2).active()).toBe(false);
1801
1802 // Doesn't matter
1803 menu.pageDown();
1804
1805 expect(menu.shownItem(0).lcField()).toEqual(' corpusid');
1806 expect(menu.shownItem(0).active()).toBe(false);
1807 expect(menu.shownItem(1).active()).toBe(false);
1808 expect(menu.shownItem(2).active()).toBe(false);
1809 expect(menu.container().items[0].active()).toBe(false);
1810 expect(menu.container().items[1].active()).toBe(false);
1811 expect(menu.container().items[2].active()).toBe(false); //prefix
1812 });
1813
1814 it('should be page downable with prefix', function () {
1815 var menu = OwnContainerMenu.create(demolonglist,ExampleItemList);
1816 menu.limit(3);
1817
1818 expect(menu.prefix('e').show(0)).toBe(true);
1819
1820 expect(menu.shownItem(0).active()).toBe(true);
1821 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1822 expect(menu.shownItem(1).active()).toBe(false);
1823 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1824 expect(menu.shownItem(2).active()).toBe(false);
1825 expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum');
1826 expect(menu.shownItem(3)).toBe(undefined);
1827
1828 expect(menu.container().items[0].active()).toBe(false);
1829 expect(menu.container().items[1].active()).toBe(false);
1830 expect(menu.container().items[2].active()).toBe(false); //prefix
1831
1832 menu.pageDown();
1833
1834 expect(menu.shownItem(0).active()).toBe(false);
1835 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1836 expect(menu.shownItem(1).active()).toBe(false);
1837 expect(menu.shownItem(1).lcField()).toEqual(' genre');
1838 expect(menu.shownItem(2).active()).toBe(false);
1839 expect(menu.shownItem(2).lcField()).toEqual(' textid');
1840
1841 // Doesn't matter
1842 menu.pageDown();
1843
1844 expect(menu.shownItem(0).active()).toBe(false);
1845 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1846 expect(menu.shownItem(1).active()).toBe(false);
1847 expect(menu.shownItem(1).lcField()).toEqual(' genre');
1848 expect(menu.shownItem(2).active()).toBe(false);
1849 expect(menu.shownItem(2).lcField()).toEqual(' textid');
1850 expect(menu.container().items[0].active()).toBe(false);
1851 expect(menu.container().items[1].active()).toBe(false);
1852 expect(menu.container().items[2].active()).toBe(false); //prefix
1853 });
1854
1855
1856 it('should be page upable', function () {
1857 var menu = OwnContainerMenu.create(demolonglist,ExampleItemList);
1858 menu.limit(3);
1859
1860 // Choose the final value
1861 expect(menu.show(1000)).toBe(true);
1862
1863 expect(menu.shownItem(0).active()).toBe(false);
1864 expect(menu.shownItem(1).active()).toBe(false);
1865 expect(menu.shownItem(2).active()).toBe(true);
1866 expect(menu.shownItem(2).lcField()).toEqual(' textid');
1867 expect(menu.shownItem(3)).toBe(undefined);
1868 expect(menu.container().items[0].active()).toBe(false);
1869 expect(menu.container().items[1].active()).toBe(false);
1870 expect(menu.container().items[2].active()).toBe(false); //prefix
1871
1872 menu.pageUp();
1873
1874 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1875 expect(menu.shownItem(0).active()).toBe(false);
1876 expect(menu.shownItem(1).active()).toBe(false);
1877 expect(menu.shownItem(2).active()).toBe(false);
1878
1879 menu.pageUp();
1880
1881 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1882 expect(menu.shownItem(0).active()).toBe(false);
1883 expect(menu.shownItem(1).active()).toBe(false);
1884 expect(menu.shownItem(2).active()).toBe(false);
1885
1886 // Doesn't matter
1887 menu.pageUp();
1888
1889 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1890 expect(menu.shownItem(0).active()).toBe(false);
1891 expect(menu.shownItem(1).active()).toBe(false);
1892 expect(menu.shownItem(2).active()).toBe(false);
1893 expect(menu.container().items[0].active()).toBe(false);
1894 expect(menu.container().items[1].active()).toBe(false);
1895 expect(menu.container().items[2].active()).toBe(false); //prefix
1896 });
1897
1898 it('should be page upable with prefix', function () {
1899 var menu = OwnContainerMenu.create(demolonglist,ExampleItemList);
1900 menu.limit(3);
1901
1902 // Choose the final value
1903 expect(menu.prefix("e").show(1000)).toBe(true);
1904
1905 expect(menu.shownItem(0).active()).toBe(false);
1906 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1907 expect(menu.shownItem(1).active()).toBe(false);
1908 expect(menu.shownItem(1).lcField()).toEqual(' genre');
1909 expect(menu.shownItem(2).active()).toBe(true);
1910 expect(menu.shownItem(2).lcField()).toEqual(' textid');
1911 expect(menu.shownItem(3)).toBe(undefined);
1912 expect(menu.container().items[0].active()).toBe(false);
1913 expect(menu.container().items[1].active()).toBe(false);
1914 expect(menu.container().items[2].active()).toBe(false); //prefix
1915
1916 menu.pageUp();
1917
1918 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1919 expect(menu.shownItem(0).active()).toBe(false);
1920 expect(menu.shownItem(1).active()).toBe(false);
1921 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1922 expect(menu.shownItem(2).active()).toBe(false);
1923 expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum');
1924
1925 // Doesn't matter
1926 menu.pageUp();
1927
1928 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1929 expect(menu.shownItem(0).active()).toBe(false);
1930 expect(menu.shownItem(1).active()).toBe(false);
1931 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1932 expect(menu.shownItem(2).active()).toBe(false);
1933 expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum');
1934 expect(menu.container().items[0].active()).toBe(false);
1935 expect(menu.container().items[1].active()).toBe(false);
1936 expect(menu.container().items[2].active()).toBe(false); //prefix
1937 });
1938
1939 it('should be view upable and downable (1)', function () {
1940 var menu = OwnContainerMenu.create(demolonglist,ExampleItemList);
1941 menu.limit(7);
1942
1943 // Choose the final value
1944 expect(menu.show(1)).toBe(true);
1945
1946 expect(menu.shownItem(0).active()).toBe(false);
1947 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1948 expect(menu.shownItem(1).active()).toBe(true);
1949 expect(menu.shownItem(2).active()).toBe(false);
1950 expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum');
1951 expect(menu.shownItem(6).active()).toBe(false);
1952 expect(menu.shownItem(7)).toBe(undefined);
1953 expect(menu.container().items[0].active()).toBe(false);
1954 expect(menu.container().items[1].active()).toBe(false);
1955 expect(menu.container().items[2].active()).toBe(false); //prefix
1956
1957 // Doesn't change anything
1958 menu.viewUp();
1959
1960 expect(menu.shownItem(0).active()).toBe(false);
1961 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1962 expect(menu.shownItem(1).active()).toBe(true);
1963
1964 menu.viewDown();
1965
1966 expect(menu.shownItem(0).active()).toBe(true);
1967 expect(menu.shownItem(0).lcField()).toEqual(' untertitel');
1968 expect(menu.shownItem(1).active()).toBe(false);
1969
1970 menu.viewDown();
1971
1972 expect(menu.shownItem(0).active()).toBe(false);
1973 expect(menu.shownItem(0).lcField()).toEqual(' veröffentlichungsdatum');
1974 expect(menu.shownItem(1).active()).toBe(false);
1975
1976 // No effect anymore
1977 menu.viewDown();
1978
1979 expect(menu.shownItem(0).active()).toBe(false);
1980 expect(menu.shownItem(0).lcField()).toEqual(' veröffentlichungsdatum');
1981 expect(menu.shownItem(1).active()).toBe(false);
1982 expect(menu.container().items[0].active()).toBe(false);
1983 expect(menu.container().items[1].active()).toBe(false);
1984 expect(menu.container().items[2].active()).toBe(false); //prefix
1985 });
1986
1987 it('should be view upable and downable (2)', function () {
1988
1989 // List is longer than limit
1990 var menu = OwnContainerMenu.create(demolist,ExampleItemList);
1991 menu.limit(7);
1992
1993 // Choose the final value
1994 expect(menu.show(1)).toBe(true);
1995
1996 expect(menu.shownItem(0).active()).toBe(false);
1997 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1998 expect(menu.shownItem(1).active()).toBe(true);
1999 expect(menu.shownItem(2).active()).toBe(false);
2000 expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum');
2001 expect(menu.shownItem(4).active()).toBe(false);
2002 expect(menu.shownItem(5)).toBe(undefined);
2003 expect(menu.container().items[0].active()).toBe(false);
2004 expect(menu.container().items[1].active()).toBe(false);
2005 expect(menu.container().items[2].active()).toBe(false); //prefix
2006
2007 // Doesn't change anything
2008 menu.viewUp();
2009
2010 expect(menu.shownItem(0).active()).toBe(false);
2011 expect(menu.shownItem(0).lcField()).toEqual(' titel');
2012 expect(menu.shownItem(1).active()).toBe(true);
2013
2014 menu.viewDown();
2015
2016 expect(menu.shownItem(0).active()).toBe(false);
2017 expect(menu.shownItem(0).lcField()).toEqual(' titel');
2018 expect(menu.shownItem(1).active()).toBe(true);
2019 expect(menu.container().items[0].active()).toBe(false);
2020 expect(menu.container().items[1].active()).toBe(false);
2021 expect(menu.container().items[2].active()).toBe(false); //prefix
2022 });
2023
2024
2025 it('should scroll to a chosen value (1)', function () {
2026 var menu = OwnContainerMenu.create(demolist,ExampleItemList);
2027 menu.limit(3);
2028
2029 // Choose value 1
2030 expect(menu.show(1)).toBe(true);
2031
2032 expect(menu.shownItem(0).active()).toBe(false);
2033 expect(menu.shownItem(0).lcField()).toEqual(' titel');
2034 expect(menu.shownItem(1).active()).toBe(true);
2035 expect(menu.shownItem(2).active()).toBe(false);
2036 expect(menu.shownItem(3)).toBe(undefined);
2037 expect(menu.container().items[0].active()).toBe(false);
2038 expect(menu.container().items[1].active()).toBe(false);
2039 expect(menu.container().items[2].active()).toBe(false); //prefix
2040
2041 // Choose value 2
2042 expect(menu.show(2)).toBe(true);
2043
2044 expect(menu.shownItem(0).active()).toBe(false);
2045 expect(menu.shownItem(0).lcField()).toEqual(' titel');
2046 expect(menu.shownItem(1).active()).toBe(false);
2047 expect(menu.shownItem(2).active()).toBe(true);
2048 expect(menu.shownItem(3)).toBe(undefined);
2049 });
2050
2051 it('should scroll to a chosen value (2)', function () {
2052 var menu = OwnContainerMenu.create(demolonglist,ExampleItemList);
2053
2054 // Choose value 3
2055 expect(menu.limit(3).show(3)).toBe(true);
2056 expect(menu.shownItem(0).lcField()).toEqual(' länge');
2057 expect(menu.shownItem(0).active()).toBe(true);
2058 expect(menu.shownItem(1).active()).toBe(false);
2059 expect(menu.shownItem(2).active()).toBe(false);
2060 expect(menu.shownItem(3)).toBe(undefined);
2061 });
2062
2063 xit('should scroll to a chosen value after prefixing, if the chosen value is live');
2064
2065 it('should be extendable', function () {
2066 var menu = OwnContainerMenu.create([],ExampleItemList);
2067 let entryData = 'empty';
2068 menu._itemClass = menuItemClass;
2069 menu.readItems([
2070 ['a', '', function () { entryData = 'a' }],
2071 ['bb', '', function () { entryData = 'bb' }],
2072 ['ccc', '', function () { entryData = 'ccc' }],
2073 ]);
2074 expect(menu.limit(3).show(3)).toBe(true);
2075 expect(menu.shownItem(0).lcField()).toEqual(' a');
2076 expect(menu.shownItem(1).lcField()).toEqual(' bb');
2077 expect(menu.shownItem(2).lcField()).toEqual(' ccc');
2078 expect(entryData).toEqual('empty');
2079 menu.shownItem(1).element().click();
2080 expect(entryData).toEqual('bb');
2081 expect(menu.lengthField().element().innerText).toEqual("a--bb--ccc--")
2082 expect(menu.slider().length()).toEqual(3);
2083 let obj = menu.itemClass().create(
2084 ['dddd','',function () { entryData = 'dddd'} ]
2085 );
2086 menu.append(obj);
2087 expect(menu.limit(2).show(1)).toBe(true);
2088 expect(menu.shownItem(0).lcField()).toEqual(' a');
2089 expect(menu.shownItem(1).lcField()).toEqual(' bb');
2090 menu.next();
2091 expect(menu.shownItem(1).lcField()).toEqual(' ccc');
2092 menu.next();
2093 expect(menu.shownItem(1).lcField()).toEqual(' dddd');
2094 menu.next();
2095 menu.next();
2096 menu.next();
2097 expect(menu.shownItem(0).lcField()).toEqual(' a');
2098 expect(menu.lengthField().element().innerText).toEqual("a--bb--ccc--dddd--")
2099 expect(menu.slider().length()).toEqual(4);
2100 });
2101 });
Leo Reppc66268e2021-10-28 11:44:35 +02002102
2103 describe('KorAP.ContainerMenu.Container', function () {
Leo Reppd162b2e2021-06-30 13:51:07 +02002104 it("should be initializable with no additional container items", function () {
2105 var list = [
2106 ["Constituency"],
2107 ["Lemma"],
2108 ["Morphology"],
2109 ["Part-of-Speech"],
2110 ["Syntax"]
2111 ];
2112 var menu = OwnContainerMenu.create(list);
2113 var container = menu.container();
2114 expect(container._containerItemClass).toEqual(OwnContainerItemClass);
2115 expect(container.element().nodeName).toEqual("UL");
2116 expect(container.element().classList.contains("menu")).toBeTruthy();
2117 expect(container.element().classList.contains("visible")).toBeFalsy();
2118 expect(menu._prefix).toEqual(container._prefix);
2119 expect(container.length()).toEqual(1);
2120 expect(container.length()).toEqual(container.items.length);
2121 expect(container.liveLength()).toEqual(0);
2122 expect(container.item(0)).toEqual(container._prefix);
2123 expect(container.active()).toBeFalsy();
Leo Reppdedcf1a2021-08-18 18:57:47 +02002124 expect(directElementChildrenByTagName(menu.element(),"pref")).toEqual([]);
Leo Reppd162b2e2021-06-30 13:51:07 +02002125 expect(container.element().getElementsByClassName("pref").length).toEqual(1);
2126
2127
2128
2129 menu.prefix("ad");
2130 expect(container.liveLength()).toEqual(1);
2131 menu.prev();
2132 expect(container.active()).toBeTruthy();
Leo Reppd162b2e2021-06-30 13:51:07 +02002133 });
2134
2135 });
2136 });