blob: 883a71d44345998540458a16b14bbecdf0ffb88c [file] [log] [blame]
Akronaba7a5a2016-08-15 21:58:33 +02001define(
2 ['menu', 'menu/item', 'menu/prefix', 'menu/lengthField'],
3 function (menuClass, menuItemClass, prefixClass, lengthFieldClass) {
Akron1ff3ac22016-04-28 16:30:45 +02004
Akronaba7a5a2016-08-15 21:58:33 +02005 // The OwnMenu item
6 KorAP.OwnMenuItem = {
7 create : function (params) {
8 return Object.create(menuItemClass).upgradeTo(KorAP.OwnMenuItem)._init(params);
9 },
10 content : function (content) {
11 if (arguments.length === 1) {
12 this._content = content;
13 };
14 return this._content;
15 },
16 _init : function (params) {
17 if (params[0] === undefined)
18 throw new Error("Missing parameters");
Nils Diewald7c8ced22015-04-15 19:21:00 +000019
Akronaba7a5a2016-08-15 21:58:33 +020020 this._content = document.createTextNode(params[0]);
21 this._lcField = ' ' + this.content().textContent.toLowerCase();
Nils Diewald7c8ced22015-04-15 19:21:00 +000022
Akronaba7a5a2016-08-15 21:58:33 +020023 return this;
24 }
25 };
Nils Diewald7c8ced22015-04-15 19:21:00 +000026
Akronaba7a5a2016-08-15 21:58:33 +020027 // The OwnMenu
28 KorAP.OwnMenu = {
29 create : function (list) {
30 return Object.create(menuClass)
31 .upgradeTo(KorAP.OwnMenu)
32 ._init(list, { itemClass : KorAP.OwnMenuItem });
33 }
34 };
Nils Diewaldfda29d92015-01-22 17:28:01 +000035
Nils Diewaldfda29d92015-01-22 17:28:01 +000036
Akronaba7a5a2016-08-15 21:58:33 +020037 // HintMenuItem
38 KorAP.HintMenuItem = {
39 create : function (params) {
40 return Object.create(menuItemClass)
41 .upgradeTo(KorAP.HintMenuItem)
42 ._init(params);
43 },
44 content : function (content) {
45 if (arguments.length === 1) {
46 this._content = content;
47 };
48 return this._content;
49 },
50 _init : function (params) {
51 if (params[0] === undefined || params[1] === undefined)
52 throw new Error("Missing parameters");
Nils Diewald7c8ced22015-04-15 19:21:00 +000053
Akronaba7a5a2016-08-15 21:58:33 +020054 this._name = params[0];
55 this._action = params[1];
56 this._lcField = ' ' + this._name.toLowerCase();
Nils Diewald7c8ced22015-04-15 19:21:00 +000057
Akronaba7a5a2016-08-15 21:58:33 +020058 if (params.length > 2) {
59 this._desc = params[2];
60 this._lcField += " " + this._desc.toLowerCase();
61 };
62
63 return this;
64 },
Nils Diewald7c8ced22015-04-15 19:21:00 +000065
Akronaba7a5a2016-08-15 21:58:33 +020066 name : function () {
67 return this._name;
68 },
69 action : function () {
70 return this._action;
71 },
72 desc : function () {
73 return this._desc;
74 },
75 element : function () {
76 // already defined
Akron24aa0052020-11-10 11:00:34 +010077 if (this._el !== undefined)
78 return this._el;
Nils Diewald7c8ced22015-04-15 19:21:00 +000079
Akronaba7a5a2016-08-15 21:58:33 +020080 // Create list item
81 var li = document.createElement("li");
82 li.setAttribute("data-action", this._action);
Nils Diewald7c8ced22015-04-15 19:21:00 +000083
Akronaba7a5a2016-08-15 21:58:33 +020084 // Create title
85 var name = document.createElement("strong");
86 name.appendChild(document.createTextNode(this._name));
87
88 li.appendChild(name);
Nils Diewald7c8ced22015-04-15 19:21:00 +000089
Akronaba7a5a2016-08-15 21:58:33 +020090 // Create description
91 if (this._desc !== undefined) {
92 var desc = document.createElement("span");
93 desc.appendChild(document.createTextNode(this._desc));
94 li.appendChild(desc);
95 };
Akron24aa0052020-11-10 11:00:34 +010096 return this._el = li;
Akronaba7a5a2016-08-15 21:58:33 +020097 }
98 };
99
100
101 // HintMenu
102 KorAP.HintMenu = {
103 create : function (context, list) {
104 var obj = Object.create(menuClass)
105 .upgradeTo(KorAP.HintMenu)
106 ._init(list, {itemClass : KorAP.HintMenuItem});
107 obj._context = context;
108 return obj;
109 }
110 };
111
112
113 // The ComplexMenuItem
114 KorAP.ComplexMenuItem = {
115 create : function (params) {
116 return Object.create(menuItemClass)
117 .upgradeTo(KorAP.ComplexMenuItem)
118 ._init(params);
119 },
120 content : function (content) {
121 if (arguments.length === 1) {
122 this._content = content;
123 };
124 return this._content;
125 },
126 _init : function (params) {
127 if (params[0] === undefined)
128 throw new Error("Missing parameters");
129
130 var r = document.createElement('div');
131 for (var i = 1; i <= params.length; i++) {
132 var h = document.createElement('h' + i);
133 h.appendChild(document.createTextNode(params[i-1]));
134 r.appendChild(h);
135 };
136
137 this._content = r;
138 this._lcField = ' ' + this.content().textContent.toLowerCase();
139
140 return this;
141 }
142 };
143
144
145 describe('KorAP.MenuItem', function () {
146 it('should be initializable', function () {
147 expect(
148 function() { menuItemClass.create([]) }
149 ).toThrow(new Error("Missing parameters"));
150
151 expect(
152 function() { KorAP.OwnMenuItem.create([]) }
153 ).toThrow(new Error("Missing parameters"));
154
155 var mi = KorAP.OwnMenuItem.create(["Baum"]);
156 expect(mi.element().firstChild.nodeValue).toEqual('Baum');
157 expect(mi.lcField()).toEqual(' baum');
158 });
159
160 it('shouldn\'t have a reference to the menu', function () {
161 var menuItem = KorAP.OwnMenuItem.create(['Test']);
162 expect(menuItem.menu()).toBe(undefined);
163 });
164
165 it('should be activatable and deactivateable by class', function () {
166 var menuItem = KorAP.OwnMenuItem.create(['Test']);
167
168 expect(menuItem.active()).toBe(false);
169 expect(menuItem.element().getAttribute("class")).toBe(null);
170 menuItem.active(true);
171 expect(menuItem.active()).toBe(true);
172 expect(menuItem.element().getAttribute("class")).toEqual("active");
173 menuItem.active(false); // Is active
174 expect(menuItem.active()).toBe(false);
175 expect(menuItem.element().getAttribute("class")).toEqual("");
176 menuItem.active(true);
177 expect(menuItem.active()).toBe(true);
178 expect(menuItem.element().getAttribute("class")).toEqual("active");
179
180 menuItem = KorAP.OwnMenuItem.create(['Spiegel']);
181 expect(menuItem.active()).toBe(false);
182 expect(menuItem.element().getAttribute("class")).toBe(null);
183 menuItem.active(false); // Is not active
184 expect(menuItem.active()).toBe(false);
185 expect(menuItem.element().getAttribute("class")).toBe(null);
186 });
187
188 it('should be set to boundary', function () {
189 var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']);
190 expect(menuItem.active()).toBe(false);
191 expect(menuItem.element().getAttribute("class")).toBe(null);
192
193 // Set active
194 menuItem.active(true);
195 expect(menuItem.active()).toBe(true);
196 expect(menuItem.noMore()).toBe(false);
197 expect(menuItem.element().getAttribute("class")).toEqual("active");
198
199 // Set no more
200 menuItem.noMore(true);
201 expect(menuItem.active()).toBe(true);
202 expect(menuItem.noMore()).toBe(true);
203 expect(menuItem.element().getAttribute("class")).toEqual("active no-more");
204
205 // No no more
206 menuItem.noMore(false);
207 expect(menuItem.active()).toBe(true);
208 expect(menuItem.noMore()).toBe(false);
209 expect(menuItem.element().getAttribute("class")).toEqual("active");
210
211 // Set no more, deactivate
212 menuItem.noMore(true);
213 menuItem.active(false);
214 expect(menuItem.active()).toBe(false);
215 expect(menuItem.noMore()).toBe(true);
216 expect(menuItem.element().getAttribute("class")).toEqual("no-more");
217
218 // Set active
219 menuItem.active(true);
220 expect(menuItem.active()).toBe(true);
221 expect(menuItem.noMore()).toBe(true);
222 expect(menuItem.element().getAttribute("class")).toEqual("no-more active");
223 });
224
225
226 it('should be highlightable', function () {
227 // Highlight in the middle
228 var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']);
229 menuItem.highlight("ren");
230 expect(menuItem.element().innerHTML).toEqual("Co<mark>reN</mark>LP");
231
232 menuItem.lowlight();
233 expect(menuItem.element().innerHTML).toEqual("CoreNLP");
234
235 var plain = "<div><h1>CoreNLP</h1><h2>corenlp/</h2></div>";
236
237 // Starting highlight
238 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
239 menuItem.highlight("cor");
240 expect(menuItem.element().innerHTML).toEqual("<div><h1><mark>Cor</mark>eNLP</h1><h2><mark>cor</mark>enlp/</h2></div>");
241
242 menuItem.lowlight();
243 expect(menuItem.element().innerHTML).toEqual(plain);
244
245 // Starting highlight - short
246 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
247 menuItem.highlight("c");
248 expect(menuItem.element().innerHTML).toEqual("<div><h1><mark>C</mark>oreNLP</h1><h2><mark>c</mark>orenlp/</h2></div>");
249
250 menuItem.lowlight();
251 expect(menuItem.element().innerHTML).toEqual(plain);
252
253 // Highlight at the end
254 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
255 menuItem.highlight("nlp");
256 expect(menuItem.element().innerHTML).toEqual("<div><h1>Core<mark>NLP</mark></h1><h2>core<mark>nlp</mark>/</h2></div>");
257
258 menuItem.lowlight();
259 expect(menuItem.element().innerHTML).toEqual(plain);
260
261 // Highlight at the end - short
262 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
263 menuItem.highlight("p");
264 expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNL<mark>P</mark></h1><h2>corenl<mark>p</mark>/</h2></div>");
265
266 menuItem.lowlight();
267 expect(menuItem.element().innerHTML).toEqual(plain);
268
269 // No highlight
270 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
271 menuItem.highlight("xp");
272 expect(menuItem.element().innerHTML).toEqual(plain);
273
274 menuItem.lowlight();
275 expect(menuItem.element().innerHTML).toEqual(plain);
276
277 // Highlight in the middle - first
278 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
279 menuItem.highlight("ren");
280 expect(menuItem.element().innerHTML).toEqual("<div><h1>Co<mark>reN</mark>LP</h1><h2>co<mark>ren</mark>lp/</h2><h3>This is my Example</h3></div>");
281
282 plain = "<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Example</h3></div>"
283
284 menuItem.lowlight();
285 expect(menuItem.element().innerHTML).toEqual(plain);
286
287 // Highlight in the middle - second
288 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
289 menuItem.highlight("ampl");
290 expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Ex<mark>ampl</mark>e</h3></div>");
291
292 menuItem.lowlight();
293 expect(menuItem.element().innerHTML).toEqual(plain);
294
295 // Highlight in the middle - both
296 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
297 menuItem.highlight("e");
Akronacffc652017-12-18 21:21:25 +0100298
Akronaba7a5a2016-08-15 21:58:33 +0200299 expect(menuItem.element().innerHTML).toEqual("<div><h1>Cor<mark>e</mark>NLP</h1><h2>cor<mark>e</mark>nlp/</h2><h3>This is my <mark>E</mark>xampl<mark>e</mark></h3></div>");
300
301 menuItem.lowlight();
302 expect(menuItem.element().innerHTML).toEqual(plain);
303
304 // Highlight in the end - second
305 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
306 menuItem.highlight("le");
307 expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Examp<mark>le</mark></h3></div>");
308
309 menuItem.lowlight();
310 expect(menuItem.element().innerHTML).toEqual(plain);
311
312 // Highlight at the beginning - second
313 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
314 menuItem.highlight("this");
315 expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3><mark>This</mark> is my Example</h3></div>");
316
317 menuItem.lowlight();
318 expect(menuItem.element().innerHTML).toEqual(plain);
319 });
320 });
321
322
323 describe('KorAP.Menu', function () {
324 var list = [
325 ["Constituency", "c=", "Example 1"],
326 ["Lemma", "l="],
327 ["Morphology", "m=", "Example 2"],
328 ["Part-of-Speech", "p="],
329 ["Syntax", "syn="]
330 ];
331
Akronacffc652017-12-18 21:21:25 +0100332 var listMultiPrefix = [
333 ["PP","PP ","Personal Pronoun"],
334 ["PPP","PPP ","Personal Pronoun, Plural"],
335 ["PPPA","PPPA ","Personal Pronoun, Plural, Acc."],
336 ["PPPD","PPPD ","Personal Pronoun, Plural, Dative"],
337 ["PPPR","PPPR ","Personal Pronoun, Plural, Direct"],
338 ["PPPO","PPPO ","Personal Pronoun, Plural, Oblique"],
339 ["PPS","PPS ","Personal Pronoun, Singular"],
340 ["PPSA","PPSA ","Personal Pronoun, Singular, Accusative"],
341 ["PPSD","PPSD ","Personal Pronoun, Singular, Dative"],
342 ["PPSR","PPSR ","Personal Pronoun, Singular, Direct"],
343 ["PPSN","PPSN ","Personal Pronoun, Singular, Nominative"],
344 ["PPSO","PPSO ","Personal Pronoun, Singular, Oblique"]
345 ];
346
Akronaba7a5a2016-08-15 21:58:33 +0200347 var demolist = [
348 ['Titel', 'title'],
349 ['Untertitel', 'subTitle'],
350 ['Veröffentlichungsdatum', 'pubDate'],
351 ['Länge', 'length'],
352 ['Autor', 'author']
353 ];
354
355 var demolonglist = [
356 ['Titel', 'title'],
357 ['Untertitel', 'subTitle'],
358 ['Veröffentlichungsdatum', 'pubDate'],
359 ['Länge', 'length'],
360 ['Autor', 'author'],
361 ['Genre', 'genre'],
362 ['corpusID', 'corpusID'],
363 ['docID', 'docID'],
364 ['textID', 'textID'],
365 ];
366
367 it('should be initializable', function () {
368 var list = [
369 ["Constituency"],
370 ["Lemma"],
371 ["Morphology"],
372 ["Part-of-Speech"],
373 ["Syntax"]
374 ];
375
376 var menu = KorAP.OwnMenu.create(list);
hebastaa7806882019-11-18 19:35:47 +0100377 expect(menu.dontHide).toBe(false);
Akronaba7a5a2016-08-15 21:58:33 +0200378 menu._firstActive = true;
379 expect(menu.itemClass()).toEqual(KorAP.OwnMenuItem);
380 expect(menu.element().nodeName).toEqual('UL');
381 expect(menu.element().classList.contains('visible')).toBeFalsy();
382 expect(menu.limit()).toEqual(8);
Leo Repp56904d22021-04-26 15:53:22 +0200383 expect(menu._notItemElements).toEqual(3);
Akronaba7a5a2016-08-15 21:58:33 +0200384
385 menu.limit(9);
386 expect(menu.limit()).toEqual(9);
387
388 menu.limit(8);
389
390 // view
391 menu.show();
392
393 // First element in list
394 expect(menu.item(0).active()).toBe(true);
395 expect(menu.item(0).noMore()).toBe(true);
396
397 // Middle element in list
398 expect(menu.item(2).active()).toBe(false);
399 expect(menu.item(2).noMore()).toBe(false);
400
401 // Last element in list
402 expect(menu.item(menu.length() - 1).active()).toBe(false);
403 expect(menu.item(menu.length() - 1).noMore()).toBe(true);
404 });
405
406 it('should have a reference to the menu', function () {
407 var menu = KorAP.HintMenu.create("cnx/", list);
408 expect(menu.item(0).menu()).toEqual(menu);
409
410 menu = KorAP.HintMenu.create("cnx/", list);
411 expect(menu.element().menu).toEqual(menu);
412 });
Leo Reppafcf9842021-06-30 13:01:09 +0200413
414 it('should only remove direct descendants with removeItems', function () {
415 var menu = KorAP.HintMenu.create("cnx/", list);
416 var newUL = document.createElement("ul");
417 var newLI = document.createElement("li");
418 newUL.appendChild(newLI);
419 //This is a very constructed example, but this actually happens within containerMenu
420 menu.element().appendChild(newUL);
421 expect(menu.element().childNodes[3].nodeName).toEqual("UL");
422 expect(menu.element().childNodes[3].childNodes[0]).toEqual(newLI);
423 menu.prefix("a"); //to call show
424 expect(menu.element().childNodes[3].nodeName).toEqual("UL");
425 expect(menu.element().childNodes[3].childNodes[0]).toEqual(newLI);
426
427 });
Akronaba7a5a2016-08-15 21:58:33 +0200428
429
430 it('should be visible', function () {
431 var menu = KorAP.HintMenu.create("cnx/", list);
432 expect(menu.removeItems()).toBe(undefined);
433 menu.limit(3);
434
435 expect(menu.show()).toBe(true);
436
Leo Repp7b0fbf92021-07-14 11:25:59 +0200437 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
438 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>");
439 expect(menu.directElementChildrenByTagName("li")[1].getAttribute("data-action")).toEqual("l=");
440 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
441 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Akronaba7a5a2016-08-15 21:58:33 +0200442
443 // Check boundaries
Leo Repp7b0fbf92021-07-14 11:25:59 +0200444 expect(menu.directElementChildrenByTagName("li")[0].classList.contains("no-more")).toBe(true);
445 expect(menu.directElementChildrenByTagName("li")[1].classList.contains("no-more")).toBe(false);
446 expect(menu.directElementChildrenByTagName("li")[2].classList.contains("no-more")).toBe(false);
Akronaba7a5a2016-08-15 21:58:33 +0200447 });
448
449 it('should be filterable', function () {
450 var menu = KorAP.HintMenu.create("cnx/", list);
451 menu.limit(3);
452 expect(menu.prefix("o").show()).toBe(true);
Leo Repp524320f2021-05-14 11:33:09 +0200453 expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("o");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200454 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
455 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
456 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
457 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Akronaba7a5a2016-08-15 21:58:33 +0200458
459 // Check boundaries
Leo Repp7b0fbf92021-07-14 11:25:59 +0200460 expect(menu.directElementChildrenByTagName("li")[0].classList.contains("no-more")).toBe(true);
461 expect(menu.directElementChildrenByTagName("li")[1].classList.contains("no-more")).toBe(false);
462 expect(menu.directElementChildrenByTagName("li")[2].classList.contains("no-more")).toBe(true);
Akronaba7a5a2016-08-15 21:58:33 +0200463
464 menu.limit(2);
465
466 expect(menu.prefix("o").show()).toBe(true);
Leo Repp524320f2021-05-14 11:33:09 +0200467 expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("o");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200468 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
469 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
470 expect(menu.directElementChildrenByTagName("li")[2]).toBe(undefined);
Akronaba7a5a2016-08-15 21:58:33 +0200471
472 // Check boundaries
Leo Repp7b0fbf92021-07-14 11:25:59 +0200473 expect(menu.directElementChildrenByTagName("li")[0].classList.contains("no-more")).toBe(true);
474 expect(menu.directElementChildrenByTagName("li")[1].classList.contains("no-more")).toBe(false);
475 expect(menu.directElementChildrenByTagName("li")[2]).toBe(undefined);
Akronaba7a5a2016-08-15 21:58:33 +0200476
477 expect(menu.prefix("e").show()).toBe(true);
Leo Repp524320f2021-05-14 11:33:09 +0200478 expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("e");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200479 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
480 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
481 expect(menu.directElementChildrenByTagName("li")[2]).toBe(undefined);
Akronaba7a5a2016-08-15 21:58:33 +0200482
483 menu.limit(5);
484 expect(menu.prefix("a").show()).toBe(true);
Leo Repp524320f2021-05-14 11:33:09 +0200485 expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("a");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200486 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Ex<mark>a</mark>mple 1</span>");
487 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Lemm<mark>a</mark></strong>");
488 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Ex<mark>a</mark>mple 2</span>");
489 expect(menu.directElementChildrenByTagName("li")[3].innerHTML).toEqual("<strong>P<mark>a</mark>rt-of-Speech</strong>");
490 expect(menu.directElementChildrenByTagName("li")[4].innerHTML).toEqual("<strong>Synt<mark>a</mark>x</strong>");
491 expect(menu.directElementChildrenByTagName("li")[5]).toBe(undefined);
Akronaba7a5a2016-08-15 21:58:33 +0200492 });
493
Akronaba7a5a2016-08-15 21:58:33 +0200494 it('should be nextable', function () {
495 var menu = KorAP.HintMenu.create("cnx/", list);
496 menu._firstActive = true;
497
498 // Show only 3 items
499 menu.limit(3);
500 expect(menu.show()).toBe(true);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200501 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200502 expect(menu.shownItem(0).active()).toBe(true);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200503 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200504 expect(menu.shownItem(1).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200505 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200506 expect(menu.shownItem(2).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200507 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Akronaba7a5a2016-08-15 21:58:33 +0200508
509 // Activate next (1)
510 menu.next();
Leo Repp7b0fbf92021-07-14 11:25:59 +0200511 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200512 expect(menu.shownItem(0).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200513 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200514 expect(menu.shownItem(1).active()).toBe(true);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200515 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200516 expect(menu.shownItem(2).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200517 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Akronaba7a5a2016-08-15 21:58:33 +0200518
519 // Activate next (2)
520 menu.next();
Leo Repp7b0fbf92021-07-14 11:25:59 +0200521 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200522 expect(menu.shownItem(0).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200523 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200524 expect(menu.shownItem(1).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200525 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200526 expect(menu.shownItem(2).active()).toBe(true);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200527 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Akronaba7a5a2016-08-15 21:58:33 +0200528
529 // Activate next (3)
530 // scroll!
531 menu.next();
Leo Repp7b0fbf92021-07-14 11:25:59 +0200532 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Lemma</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200533 expect(menu.shownItem(0).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200534 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200535 expect(menu.shownItem(1).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200536 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200537 expect(menu.shownItem(2).active()).toBe(true);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200538 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Akronaba7a5a2016-08-15 21:58:33 +0200539
540 // Activate next (4)
541 menu.next();
Leo Repp7b0fbf92021-07-14 11:25:59 +0200542 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200543 expect(menu.shownItem(0).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200544 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200545 expect(menu.shownItem(1).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200546 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Syntax</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200547 expect(menu.shownItem(2).active()).toBe(true);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200548 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Akronaba7a5a2016-08-15 21:58:33 +0200549
550 // Activate next (5) - ROLL
551 menu.next();
Leo Repp7b0fbf92021-07-14 11:25:59 +0200552 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200553 expect(menu.shownItem(0).active()).toBe(true);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200554 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200555 expect(menu.shownItem(1).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200556 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200557 expect(menu.shownItem(2).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200558 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Akronaba7a5a2016-08-15 21:58:33 +0200559
560 // Active next (6)
561 menu.next();
Leo Repp7b0fbf92021-07-14 11:25:59 +0200562 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200563 expect(menu.shownItem(0).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200564 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200565 expect(menu.shownItem(1).active()).toBe(true);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200566 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200567 expect(menu.shownItem(2).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200568 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Akronaba7a5a2016-08-15 21:58:33 +0200569 });
570
571 it('should be nextable without active field', function () {
572 var menu = KorAP.HintMenu.create("cnx/", list);
573 menu.limit(3);
574 expect(menu.show()).toBe(true);
575 menu.next();
576 expect(menu.shownItem(0).active()).toEqual(true);
577 });
578
579
580 it('should be prevable', function () {
581 var menu = KorAP.HintMenu.create("cnx/", list);
582 menu._firstActive = true;
583 menu.limit(3);
584 expect(menu.show()).toBe(true);
585
Leo Repp7b0fbf92021-07-14 11:25:59 +0200586 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200587 expect(menu.shownItem(0).active()).toBe(true);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200588 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200589 expect(menu.shownItem(1).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200590 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200591 expect(menu.shownItem(2).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200592 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Akronaba7a5a2016-08-15 21:58:33 +0200593
594 // Activate prev (1) - roll to bottom
595 menu.prev();
Leo Repp7b0fbf92021-07-14 11:25:59 +0200596 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200597 expect(menu.shownItem(0).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200598 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200599 expect(menu.shownItem(1).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200600 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Syntax</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200601 expect(menu.shownItem(2).active()).toBe(true);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200602 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Akronaba7a5a2016-08-15 21:58:33 +0200603
604 // Activate prev (2)
605 menu.prev();
Leo Repp7b0fbf92021-07-14 11:25:59 +0200606 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200607 expect(menu.shownItem(0).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200608 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200609 expect(menu.shownItem(1).active()).toBe(true);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200610 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Syntax</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200611 expect(menu.shownItem(2).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200612 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Akronaba7a5a2016-08-15 21:58:33 +0200613
614 // Activate prev (3)
615 menu.prev();
616 expect(menu.shownItem(0).name()).toEqual("Morphology");
617 expect(menu.shownItem(0).active()).toBe(true);
618 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
619 expect(menu.shownItem(1).active()).toBe(false);
620 expect(menu.shownItem(2).name()).toEqual("Syntax");
621 expect(menu.shownItem(2).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200622 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Akronaba7a5a2016-08-15 21:58:33 +0200623
624 // Activate prev (4)
625 menu.prev();
626 expect(menu.shownItem(0).name()).toEqual("Lemma");
627 expect(menu.shownItem(0).active()).toBe(true);
628 expect(menu.shownItem(1).name()).toEqual("Morphology");
629 expect(menu.shownItem(1).active()).toBe(false);
630 expect(menu.shownItem(2).name()).toEqual("Part-of-Speech");
631 expect(menu.shownItem(2).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200632 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Akronaba7a5a2016-08-15 21:58:33 +0200633
634 // Activate prev (5)
635 menu.prev();
636 expect(menu.shownItem(0).name()).toEqual("Constituency");
637 expect(menu.shownItem(0).active()).toBe(true);
638 expect(menu.shownItem(1).name()).toEqual("Lemma");
639 expect(menu.shownItem(1).active()).toBe(false);
640 expect(menu.shownItem(2).name()).toEqual("Morphology");
641 expect(menu.shownItem(2).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200642 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Akronaba7a5a2016-08-15 21:58:33 +0200643
644 // Activate next (1)
645 menu.next();
646 expect(menu.shownItem(0).name()).toEqual("Constituency");
647 expect(menu.shownItem(0).active()).toBe(false);
648 expect(menu.shownItem(1).name()).toEqual("Lemma");
649 expect(menu.shownItem(1).active()).toBe(true);
650 expect(menu.shownItem(2).name()).toEqual("Morphology");
651 expect(menu.shownItem(2).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200652 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Akronaba7a5a2016-08-15 21:58:33 +0200653
654 // Activate prev (6)
655 menu.prev();
656
657 // Activate prev (7)
658 menu.prev();
659 expect(menu.shownItem(0).name()).toEqual("Morphology");
660 expect(menu.shownItem(0).active()).toBe(false);
661 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
662 expect(menu.shownItem(1).active()).toBe(false);
663 expect(menu.shownItem(2).name()).toEqual("Syntax");
664 expect(menu.shownItem(2).active()).toBe(true);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200665 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Akronaba7a5a2016-08-15 21:58:33 +0200666 });
667
668 it('should be prevable without active field', function () {
669 var menu = KorAP.HintMenu.create("cnx/", list);
670 menu.limit(3);
671 expect(menu.show()).toBe(true);
672 menu.prev();
673 expect(menu.shownItem(2).active()).toEqual(true);
674 expect(menu.shownItem(2).lcField()).toEqual(' syntax');
675 });
676
677 it('should be navigatable and filterable (prefix = "o")', function () {
678 var menu = KorAP.HintMenu.create("cnx/", list);
679 menu._firstActive = true;
680 menu.limit(2);
681
682 expect(menu.prefix("o").show()).toBe(true);
683 expect(menu.shownItem(0).name()).toEqual("Constituency");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200684 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200685 expect(menu.shownItem(0).active()).toBe(true);
686 expect(menu.shownItem(1).name()).toEqual("Morphology");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200687 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200688 expect(menu.shownItem(1).active()).toBe(false);
689 expect(menu.shownItem(2)).toBe(undefined);
690
691 // Next (1)
692 menu.next();
693 expect(menu.shownItem(0).name()).toEqual("Constituency");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200694 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200695 expect(menu.shownItem(0).active()).toBe(false);
696 expect(menu.shownItem(1).name()).toEqual("Morphology");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200697 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200698 expect(menu.shownItem(1).active()).toBe(true);
699 expect(menu.shownItem(2)).toBe(undefined);
700
701 // Next (2)
702 menu.next();
703 expect(menu.shownItem(0).name()).toEqual("Morphology");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200704 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200705 expect(menu.shownItem(0).active()).toBe(false);
706 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200707 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200708 expect(menu.shownItem(1).active()).toBe(true);
709 expect(menu.shownItem(2)).toBe(undefined);
710
711 // Next (3) - to prefix
712 menu.next();
713 expect(menu.shownItem(0).name()).toEqual("Morphology");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200714 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200715 expect(menu.shownItem(0).active()).toBe(false);
716 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200717 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200718 expect(menu.shownItem(1).active()).toBe(false);
719 expect(menu.shownItem(2)).toBe(undefined);
720
721 menu.next();
722 expect(menu.shownItem(0).name()).toEqual("Constituency");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200723 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200724 expect(menu.shownItem(0).active()).toBe(true);
725 expect(menu.shownItem(1).name()).toEqual("Morphology");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200726 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200727 expect(menu.shownItem(1).active()).toBe(false);
728 expect(menu.shownItem(2)).toBe(undefined);
729 });
730
731
732 it('should be navigatable and filterable (prefix = "ex", "e")', function () {
733 var menu = KorAP.HintMenu.create("cnx/", list);
734 menu._firstActive = true;
735
736 menu.limit(2);
737 expect(menu.prefix("ex").show()).toBe(true);
738
739 expect(menu.shownItem(0).name()).toEqual("Constituency");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200740 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200741 expect(menu.shownItem(0).active()).toBe(true);
742 expect(menu.shownItem(1).name()).toEqual("Morphology");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200743 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200744 expect(menu.shownItem(1).active()).toBe(false);
745 expect(menu.shownItem(2)).toBe(undefined);
746
747 // Next (1)
748 menu.next();
749 expect(menu.shownItem(0).name()).toEqual("Constituency");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200750 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200751 expect(menu.shownItem(0).active()).toBe(false);
752 expect(menu.shownItem(1).name()).toEqual("Morphology");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200753 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200754 expect(menu.shownItem(1).active()).toBe(true);
755 expect(menu.shownItem(2)).toBe(undefined);
756
757 // Next (2)
758 menu.next();
759
760 expect(menu.prefix()).toEqual('ex');
761 expect(menu.shownItem(0).name()).toEqual("Constituency");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200762 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200763 expect(menu.shownItem(0).active()).toBe(false);
764
765 expect(menu.shownItem(1).name()).toEqual("Morphology");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200766 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200767 expect(menu.shownItem(1).active()).toBe(false);
768 expect(menu.shownItem(2)).toBe(undefined);
769
770 // Reset limit
771 menu.limit(5);
772
773 // Change show
774 expect(menu.prefix("e").show()).toBe(true);
775 expect(menu._prefix.active()).toBe(false);
776 expect(menu.shownItem(0).name()).toEqual("Constituency");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200777 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200778 expect(menu.shownItem(0).active()).toBe(true);
779 expect(menu.shownItem(1).name()).toEqual("Morphology");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200780 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200781 expect(menu.shownItem(1).active()).toBe(false);
782 expect(menu.shownItem(2)).toBe(undefined);
783
784 // Next (1)
785 menu.next();
786 expect(menu._prefix.active()).toBe(false);
787 expect(menu.prefix()).toEqual('e');
788 expect(menu.shownItem(0).name()).toEqual("Constituency");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200789 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200790 expect(menu.shownItem(0).active()).toBe(false);
791 expect(menu.shownItem(1).name()).toEqual("Morphology");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200792 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200793 expect(menu.shownItem(1).active()).toBe(true);
794 expect(menu.shownItem(2)).toBe(undefined);
795
796 // Next (2)
797 menu.next();
798 expect(menu._prefix.active()).toBe(true);
799 expect(menu.shownItem(0).name()).toEqual("Constituency");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200800 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200801 expect(menu.shownItem(0).active()).toBe(false);
802 expect(menu.shownItem(1).name()).toEqual("Morphology");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200803 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200804 expect(menu.shownItem(1).active()).toBe(false);
805 expect(menu.shownItem(2)).toBe(undefined);
806
807 // Next (3)
808 menu.next();
809 expect(menu._prefix.active()).toBe(false);
810 expect(menu.shownItem(0).name()).toEqual("Constituency");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200811 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200812 expect(menu.shownItem(0).active()).toBe(true);
813 expect(menu.shownItem(1).name()).toEqual("Morphology");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200814 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
Akronaba7a5a2016-08-15 21:58:33 +0200815 expect(menu.shownItem(1).active()).toBe(false);
816 expect(menu.shownItem(2)).toBe(undefined);
817 });
818
Akronacffc652017-12-18 21:21:25 +0100819 it('should be filterable (multiple prefix = "pro sin")', function () {
820 var menu = KorAP.HintMenu.create("drukola/p=", listMultiPrefix);
821 menu._firstActive = true;
822
823 menu.limit(2);
824 expect(menu.prefix("pro sin").show()).toBe(true);
825 expect(menu.shownItem(0).name()).toEqual("PPS");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200826 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual(
Akronacffc652017-12-18 21:21:25 +0100827 "<strong>PPS</strong><span>Personal <mark>Pro</mark>noun, <mark>Sin</mark>gular</span>"
828 );
829
830 expect(menu.shownItem(0).active()).toBe(true);
831 expect(menu.shownItem(1).name()).toEqual("PPSA");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200832 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>PPSA</strong><span>Personal <mark>Pro</mark>noun, <mark>Sin</mark>gular, Accusative</span>");
Akronacffc652017-12-18 21:21:25 +0100833 expect(menu.shownItem(1).active()).toBe(false);
834
835 expect(menu.shownItem(2)).toBe(undefined);
836 });
Akronaba7a5a2016-08-15 21:58:33 +0200837
Akron359c7e12017-12-19 12:06:55 +0100838 it('should be filterable (trimming = " p")', function () {
839 var menu = KorAP.HintMenu.create("/p=", listMultiPrefix);
840 // menu._firstActive = true;
841
842 menu.limit(2);
843 expect(menu.show()).toBe(true);
844 menu._prefix.add(" ");
845 expect(menu.show()).toBe(true);
846 menu._prefix.add("p")
847 expect(menu.show()).toBe(true);
848 expect(menu.shownItem(0).name()).toEqual("PP");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200849 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual(
Akron359c7e12017-12-19 12:06:55 +0100850 "<strong><mark>P</mark><mark>P</mark></strong>"+
851 "<span><mark>P</mark>ersonal <mark>P</mark>ronoun</span>"
852 );
853 });
854
855
Akronaba7a5a2016-08-15 21:58:33 +0200856 it('should choose prefix with failing prefix (1)', function () {
857 var menu = KorAP.HintMenu.create("cnx/", list);
858 menu.limit(2);
859 expect(menu.prefix("exit").show()).toBe(true);
860 expect(menu.element().querySelector('li')).toBe(null);
861 expect(menu.shownItem(0)).toBeUndefined();
862 expect(menu._prefix.active()).toBe(true);
863 });
864
865
866 it('should choose prefix with failing prefix (2)', function () {
867 var menu = KorAP.HintMenu.create("cnx/", list);
868 menu.limit(2);
869 expect(menu.show()).toBe(true);
870 expect(menu.prefix("exit").show()).toBe(true);
871 expect(menu.element().querySelector('li')).toBe(null);
872 expect(menu.shownItem(0)).toBeUndefined();
873 expect(menu._prefix.active()).toBe(true);
874 });
875
876 it('should ignore navigation with failing prefix', function () {
877 var menu = KorAP.HintMenu.create("cnx/", list);
878 menu.limit(2);
879 expect(menu.show()).toBe(true);
880
881 menu.next();
882
883 expect(menu.prefix("exit").show()).toBe(true);
884 expect(menu.element().querySelector('li')).toBe(null);
885 expect(menu.shownItem(0)).toBeUndefined();
886 expect(menu._prefix.active()).toBe(true);
887
888 menu.next();
889 expect(menu._prefix.active()).toBe(true);
890
891 menu.prev();
892 expect(menu._prefix.active()).toBe(true);
893
894 });
895
896 it('should be navigatable with prefix', function () {
897 var menu = KorAP.HintMenu.create("cnx/", demolist);
898 menu._firstActive = true;
899
900 menu.limit(3);
901
902 expect(menu.show()).toBe(true);
903 expect(menu.prefix()).toEqual("");
904
905 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200906 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200907 expect(menu.shownItem(0).active()).toBe(true);
908 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200909 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200910 expect(menu.shownItem(1).active()).toBe(false);
911 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200912 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200913 expect(menu.shownItem(2).active()).toBe(false);
914 expect(menu.shownItem(3)).toBe(undefined);
915
916 menu._prefix.add('a');
917 expect(menu.show()).toBe(true);
918 expect(menu.prefix()).toEqual("a");
919 expect(menu.shownItem(0).name()).toEqual("Autor");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200920 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200921
922 menu._prefix.add('u');
923 expect(menu.show()).toBe(true);
924 expect(menu.prefix()).toEqual("au");
925 expect(menu.shownItem(0).name()).toEqual("Autor");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200926 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong><mark>Au</mark>tor</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200927
928 menu._prefix.chop();
929 expect(menu.show()).toBe(true);
930 expect(menu.prefix()).toEqual("a");
931 expect(menu.shownItem(0).name()).toEqual("Autor");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200932 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200933
934 menu._prefix.chop();
935 expect(menu.show()).toBe(true);
936 expect(menu.prefix()).toEqual("");
937 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200938 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200939 expect(menu.shownItem(0).active()).toBe(true);
940 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200941 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200942 expect(menu.shownItem(1).active()).toBe(false);
943 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200944 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200945 expect(menu.shownItem(2).active()).toBe(false);
946 expect(menu.shownItem(3)).toBe(undefined);
947
948 // Forward
949 menu._prefix.chop();
950 expect(menu.show()).toBe(true);
951 expect(menu.prefix()).toEqual("");
952 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200953 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200954 expect(menu.shownItem(0).active()).toBe(true);
955 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200956 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200957 expect(menu.shownItem(1).active()).toBe(false);
958 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200959 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200960 expect(menu.shownItem(2).active()).toBe(false);
961
962 // Forward
963 menu.next();
964 expect(menu.prefix()).toEqual("");
965 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200966 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200967 expect(menu.shownItem(0).active()).toBe(false);
968 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200969 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200970 expect(menu.shownItem(1).active()).toBe(true);
971 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200972 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200973 expect(menu.shownItem(2).active()).toBe(false);
974 expect(menu.shownItem(3)).toBe(undefined);
975
976 // Forward
977 menu.next();
978 expect(menu.prefix()).toEqual("");
979 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200980 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200981 expect(menu.shownItem(0).active()).toBe(false);
982 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200983 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200984 expect(menu.shownItem(1).active()).toBe(false);
985 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200986 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200987 expect(menu.shownItem(2).active()).toBe(true);
988 expect(menu.shownItem(3)).toBe(undefined);
989
990 // Forward
991 menu.next();
992 expect(menu.prefix()).toEqual("");
993 expect(menu.shownItem(0).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200994 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Untertitel</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200995 expect(menu.shownItem(0).active()).toBe(false);
996 expect(menu.shownItem(1).name()).toEqual("Veröffentlichungsdatum");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200997 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Akronaba7a5a2016-08-15 21:58:33 +0200998 expect(menu.shownItem(1).active()).toBe(false);
999 expect(menu.shownItem(2).name()).toEqual("Länge");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001000 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Länge</strong>");
Akronaba7a5a2016-08-15 21:58:33 +02001001 expect(menu.shownItem(2).active()).toBe(true);
1002 expect(menu.shownItem(3)).toBe(undefined);
1003
1004 // Forward
1005 menu.next();
1006 expect(menu.prefix()).toEqual("");
1007 expect(menu.shownItem(0).name()).toEqual("Veröffentlichungsdatum");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001008 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Akronaba7a5a2016-08-15 21:58:33 +02001009 expect(menu.shownItem(0).active()).toBe(false);
1010 expect(menu.shownItem(1).name()).toEqual("Länge");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001011 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Länge</strong>");
Akronaba7a5a2016-08-15 21:58:33 +02001012 expect(menu.shownItem(1).active()).toBe(false);
1013 expect(menu.shownItem(2).name()).toEqual("Autor");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001014 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Autor</strong>");
Akronaba7a5a2016-08-15 21:58:33 +02001015 expect(menu.shownItem(2).active()).toBe(true);
1016 expect(menu.shownItem(3)).toBe(undefined);
1017
1018 // Forward
1019 menu.next();
1020 expect(menu.prefix()).toEqual("");
1021 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001022 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>");
Akronaba7a5a2016-08-15 21:58:33 +02001023 expect(menu.shownItem(0).active()).toBe(true);
1024 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001025 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>");
Akronaba7a5a2016-08-15 21:58:33 +02001026 expect(menu.shownItem(1).active()).toBe(false);
1027 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001028 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Akronaba7a5a2016-08-15 21:58:33 +02001029 expect(menu.shownItem(2).active()).toBe(false);
1030 });
1031
1032
1033 it('should be navigatable with a prefix (1)', function () {
1034 var menu = KorAP.HintMenu.create("cnx/", demolist);
1035 menu._firstActive = true;
1036
1037 menu.limit(3);
1038
1039 expect(menu.show()).toBe(true);
1040 expect(menu.prefix()).toEqual("");
1041
1042 // Add prefix in uppercase - but check in lowercase
1043 menu.prefix('El');
1044 expect(menu.show()).toBe(true);
1045
1046 expect(menu.prefix()).toEqual("El");
1047 expect(menu._prefix.active()).toEqual(false);
1048 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001049 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Akronaba7a5a2016-08-15 21:58:33 +02001050 expect(menu.shownItem(0).active()).toBe(true);
1051 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001052 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Akronaba7a5a2016-08-15 21:58:33 +02001053 expect(menu.shownItem(1).active()).toBe(false);
1054 expect(menu.shownItem(2)).toBe(undefined);
1055
1056 // Forward
1057 menu.next();
1058 expect(menu.prefix()).toEqual("El");
1059 expect(menu._prefix.active()).toEqual(false);
1060 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001061 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Akronaba7a5a2016-08-15 21:58:33 +02001062 expect(menu.shownItem(0).active()).toBe(false);
1063 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001064 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Akronaba7a5a2016-08-15 21:58:33 +02001065 expect(menu.shownItem(1).active()).toBe(true);
1066 expect(menu.shownItem(2)).toBe(undefined);
1067
1068 // Forward
1069 menu.next();
1070 expect(menu.prefix()).toEqual("El");
1071 expect(menu._prefix.active()).toEqual(true);
1072 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001073 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Akronaba7a5a2016-08-15 21:58:33 +02001074 expect(menu.shownItem(0).active()).toBe(false);
1075 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001076 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Akronaba7a5a2016-08-15 21:58:33 +02001077 expect(menu.shownItem(1).active()).toBe(false);
1078 expect(menu.shownItem(2)).toBe(undefined);
1079
1080 // Backward
1081 menu.prev();
1082 expect(menu.prefix()).toEqual("El");
1083 expect(menu._prefix.active()).toEqual(false);
1084 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001085 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Akronaba7a5a2016-08-15 21:58:33 +02001086 expect(menu.shownItem(0).active()).toBe(false);
1087
1088 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001089 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Akronaba7a5a2016-08-15 21:58:33 +02001090 expect(menu.shownItem(1).active()).toBe(true);
1091 expect(menu.shownItem(2)).toBe(undefined);
1092 });
1093
1094
1095 it('should be navigatable with a prefix (2)', function () {
1096 var menu = KorAP.HintMenu.create("cnx/", demolist);
1097 menu._firstActive = true;
1098
1099 menu.limit(3);
1100 expect(menu.show()).toBe(true);
1101 expect(menu.prefix()).toEqual("");
1102 menu.prefix('el');
1103 expect(menu.show()).toBe(true);
1104
1105 expect(menu.prefix()).toEqual("el");
1106 expect(menu._prefix.active()).toEqual(false);
1107 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001108 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Akronaba7a5a2016-08-15 21:58:33 +02001109 expect(menu.shownItem(0).active()).toBe(true);
1110 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001111 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Akronaba7a5a2016-08-15 21:58:33 +02001112 expect(menu.shownItem(1).active()).toBe(false);
1113 expect(menu.shownItem(2)).toBe(undefined);
1114
1115 // Backward
1116 menu.prev();
1117 expect(menu._prefix.active()).toEqual(true);
1118
1119 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001120 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Akronaba7a5a2016-08-15 21:58:33 +02001121 expect(menu.shownItem(0).active()).toBe(false);
1122
1123 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001124 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Akronaba7a5a2016-08-15 21:58:33 +02001125 expect(menu.shownItem(1).active()).toBe(false);
1126 expect(menu.shownItem(2)).toBe(undefined);
1127
1128 // Backward
1129 menu.prev();
1130 expect(menu._prefix.active()).toEqual(false);
1131 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001132 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Akronaba7a5a2016-08-15 21:58:33 +02001133 expect(menu.shownItem(0).active()).toBe(false);
1134 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001135 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Akronaba7a5a2016-08-15 21:58:33 +02001136 expect(menu.shownItem(1).active()).toBe(true);
1137 expect(menu.shownItem(2)).toBe(undefined);
1138 });
1139
1140 it('should be navigatable with a prefix (3)', function () {
1141 var menu = KorAP.HintMenu.create("cnx/", demolist);
1142 menu._firstActive = true;
1143 menu.limit(3);
1144 expect(menu.show()).toBe(true);
1145 expect(menu.prefix()).toEqual("");
1146 menu.prefix('el');
1147 expect(menu.show()).toBe(true);
1148
1149 expect(menu.prefix()).toEqual("el");
1150 expect(menu._prefix.active()).toEqual(false);
1151 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001152 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Akronaba7a5a2016-08-15 21:58:33 +02001153 expect(menu.shownItem(0).active()).toBe(true);
1154 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001155 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Akronaba7a5a2016-08-15 21:58:33 +02001156 expect(menu.shownItem(1).active()).toBe(false);
1157 expect(menu.shownItem(2)).toBe(undefined);
1158
1159 // Backward
1160 menu.prev();
1161 expect(menu._prefix.active()).toEqual(true);
1162 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001163 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Akronaba7a5a2016-08-15 21:58:33 +02001164 expect(menu.shownItem(0).active()).toBe(false);
1165 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001166 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Akronaba7a5a2016-08-15 21:58:33 +02001167 expect(menu.shownItem(1).active()).toBe(false);
1168 expect(menu.shownItem(2)).toBe(undefined);
1169
1170
1171 // Forward
1172 menu.next();
1173 expect(menu.prefix()).toEqual("el");
1174 expect(menu._prefix.active()).toEqual(false);
1175 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001176 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Akronaba7a5a2016-08-15 21:58:33 +02001177 expect(menu.shownItem(0).active()).toBe(true);
1178 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001179 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Akronaba7a5a2016-08-15 21:58:33 +02001180 expect(menu.shownItem(1).active()).toBe(false);
1181 expect(menu.shownItem(2)).toBe(undefined);
1182
1183 });
1184
1185 it('should show screens by offset', function () {
1186 var menu = KorAP.HintMenu.create('cnx/', demolist);
1187 menu.limit(3);
1188 expect(menu.show()).toBe(true);
1189
1190 expect(menu.shownItem(0).active()).toBe(false);
1191 expect(menu.shownItem(1).active()).toBe(false);
1192 expect(menu.shownItem(2).active()).toBe(false);
1193
1194 // Highlight the first entry
1195 menu.next();
1196
1197 expect(menu.shownItem(0).active()).toBe(true);
1198 expect(menu.shownItem(1).active()).toBe(false);
1199 expect(menu.shownItem(2).active()).toBe(false);
1200
1201 // Highlight the second entry
1202 menu.next();
1203
1204 expect(menu.shownItem(0).active()).toBe(false);
1205 expect(menu.shownItem(1).active()).toBe(true);
1206 expect(menu.shownItem(2).active()).toBe(false);
1207 expect(menu.shownItem(3)).toBe(undefined);
1208
1209 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1210 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1211
1212 // Move to first screen
1213 menu.screen(0);
1214 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1215 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1216 expect(menu.shownItem(0).active()).toBe(false);
1217 expect(menu.shownItem(1).active()).toBe(true);
1218 expect(menu.shownItem(2).active()).toBe(false);
1219 expect(menu.shownItem(3)).toBe(undefined);
1220
1221 // Move to second screen
1222 menu.screen(1);
1223 expect(menu.shownItem(0).lcField()).toEqual(' untertitel');
1224 expect(menu.shownItem(0).active()).toBe(true);
1225 expect(menu.shownItem(1).active()).toBe(false);
1226 expect(menu.shownItem(2).active()).toBe(false);
1227 expect(menu.shownItem(3)).toBe(undefined);
1228
1229 menu.screen(2);
1230 expect(menu.shownItem(0).lcField()).toEqual(' veröffentlichungsdatum');
1231 expect(menu.shownItem(0).active()).toBe(false);
1232 expect(menu.shownItem(1).active()).toBe(false);
1233 expect(menu.shownItem(2).active()).toBe(false);
1234 expect(menu.shownItem(3)).toBe(undefined);
1235
1236 menu.screen(1);
1237 expect(menu.shownItem(0).lcField()).toEqual(' untertitel');
1238 expect(menu.shownItem(0).active()).toBe(true);
1239 expect(menu.shownItem(1).active()).toBe(false);
1240 expect(menu.shownItem(2).active()).toBe(false);
1241 expect(menu.shownItem(3)).toBe(undefined);
1242 });
1243
1244 it('should show screens by offset when prefixed', function () {
1245 var menu = KorAP.HintMenu.create('cnx/', demolist);
1246 menu.limit(3);
1247 expect(menu.prefix("e").show()).toBe(true);
1248 expect(menu.shownItem(0).active()).toBe(false);
1249 expect(menu.shownItem(1).active()).toBe(false);
1250 expect(menu.shownItem(2).active()).toBe(false);
1251
1252 expect(menu.shownItem(0).element().innerHTML).toEqual('<strong>Tit<mark>e</mark>l</strong>');
1253 menu.screen(1);
1254 expect(menu.shownItem(0).element().innerHTML).toEqual('<strong>Unt<mark>e</mark>rtit<mark>e</mark>l</strong>');
1255 });
1256
1257
1258 it('should be page downable', function () {
1259 var menu = KorAP.OwnMenu.create(demolonglist);
1260 menu.limit(3);
1261
1262 expect(menu.show(0)).toBe(true);
1263
1264 expect(menu.shownItem(0).active()).toBe(true);
1265 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1266 expect(menu.shownItem(1).active()).toBe(false);
1267 expect(menu.shownItem(2).active()).toBe(false);
1268 expect(menu.shownItem(3)).toBe(undefined);
1269
1270 menu.pageDown();
1271
1272 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1273 expect(menu.shownItem(0).active()).toBe(false);
1274 expect(menu.shownItem(1).active()).toBe(false);
1275 expect(menu.shownItem(2).active()).toBe(false);
1276
1277 menu.pageDown();
1278
1279 expect(menu.shownItem(0).lcField()).toEqual(' corpusid');
1280 expect(menu.shownItem(0).active()).toBe(false);
1281 expect(menu.shownItem(1).active()).toBe(false);
1282 expect(menu.shownItem(2).active()).toBe(false);
1283
1284 // Doesn't matter
1285 menu.pageDown();
1286
1287 expect(menu.shownItem(0).lcField()).toEqual(' corpusid');
1288 expect(menu.shownItem(0).active()).toBe(false);
1289 expect(menu.shownItem(1).active()).toBe(false);
1290 expect(menu.shownItem(2).active()).toBe(false);
1291 });
1292
1293 it('should be page downable with prefix', function () {
1294 var menu = KorAP.OwnMenu.create(demolonglist);
1295 menu.limit(3);
1296
1297 expect(menu.prefix('e').show(0)).toBe(true);
1298
1299 expect(menu.shownItem(0).active()).toBe(true);
1300 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1301 expect(menu.shownItem(1).active()).toBe(false);
1302 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1303 expect(menu.shownItem(2).active()).toBe(false);
1304 expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum');
1305 expect(menu.shownItem(3)).toBe(undefined);
1306
1307 menu.pageDown();
1308
1309 expect(menu.shownItem(0).active()).toBe(false);
1310 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1311 expect(menu.shownItem(1).active()).toBe(false);
1312 expect(menu.shownItem(1).lcField()).toEqual(' genre');
1313 expect(menu.shownItem(2).active()).toBe(false);
1314 expect(menu.shownItem(2).lcField()).toEqual(' textid');
1315
1316 // Doesn't matter
1317 menu.pageDown();
1318
1319 expect(menu.shownItem(0).active()).toBe(false);
1320 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1321 expect(menu.shownItem(1).active()).toBe(false);
1322 expect(menu.shownItem(1).lcField()).toEqual(' genre');
1323 expect(menu.shownItem(2).active()).toBe(false);
1324 expect(menu.shownItem(2).lcField()).toEqual(' textid');
1325 });
1326
1327
1328 it('should be page upable', function () {
1329 var menu = KorAP.OwnMenu.create(demolonglist);
1330 menu.limit(3);
1331
1332 // Choose the final value
1333 expect(menu.show(1000)).toBe(true);
1334
1335 expect(menu.shownItem(0).active()).toBe(false);
1336 expect(menu.shownItem(1).active()).toBe(false);
1337 expect(menu.shownItem(2).active()).toBe(true);
1338 expect(menu.shownItem(2).lcField()).toEqual(' textid');
1339 expect(menu.shownItem(3)).toBe(undefined);
1340
1341 menu.pageUp();
1342
1343 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1344 expect(menu.shownItem(0).active()).toBe(false);
1345 expect(menu.shownItem(1).active()).toBe(false);
1346 expect(menu.shownItem(2).active()).toBe(false);
1347
1348 menu.pageUp();
1349
1350 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1351 expect(menu.shownItem(0).active()).toBe(false);
1352 expect(menu.shownItem(1).active()).toBe(false);
1353 expect(menu.shownItem(2).active()).toBe(false);
1354
1355 // Doesn't matter
1356 menu.pageUp();
1357
1358 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1359 expect(menu.shownItem(0).active()).toBe(false);
1360 expect(menu.shownItem(1).active()).toBe(false);
1361 expect(menu.shownItem(2).active()).toBe(false);
1362 });
1363
1364 it('should be page upable with prefix', function () {
1365 var menu = KorAP.OwnMenu.create(demolonglist);
1366 menu.limit(3);
1367
1368 // Choose the final value
1369 expect(menu.prefix("e").show(1000)).toBe(true);
1370
1371 expect(menu.shownItem(0).active()).toBe(false);
1372 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1373 expect(menu.shownItem(1).active()).toBe(false);
1374 expect(menu.shownItem(1).lcField()).toEqual(' genre');
1375 expect(menu.shownItem(2).active()).toBe(true);
1376 expect(menu.shownItem(2).lcField()).toEqual(' textid');
1377 expect(menu.shownItem(3)).toBe(undefined);
1378
1379 menu.pageUp();
1380
1381 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1382 expect(menu.shownItem(0).active()).toBe(false);
1383 expect(menu.shownItem(1).active()).toBe(false);
1384 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1385 expect(menu.shownItem(2).active()).toBe(false);
1386 expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum');
1387
1388 // Doesn't matter
1389 menu.pageUp();
1390
1391 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1392 expect(menu.shownItem(0).active()).toBe(false);
1393 expect(menu.shownItem(1).active()).toBe(false);
1394 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1395 expect(menu.shownItem(2).active()).toBe(false);
1396 expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum');
1397 });
1398
Akrone817b882018-08-31 14:09:17 +02001399 it('should be view upable and downable (1)', function () {
1400 var menu = KorAP.OwnMenu.create(demolonglist);
1401 menu.limit(7);
1402
1403 // Choose the final value
1404 expect(menu.show(1)).toBe(true);
1405
1406 expect(menu.shownItem(0).active()).toBe(false);
1407 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1408 expect(menu.shownItem(1).active()).toBe(true);
1409 expect(menu.shownItem(2).active()).toBe(false);
1410 expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum');
1411 expect(menu.shownItem(6).active()).toBe(false);
1412 expect(menu.shownItem(7)).toBe(undefined);
1413
1414 // Doesn't change anything
1415 menu.viewUp();
1416
1417 expect(menu.shownItem(0).active()).toBe(false);
1418 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1419 expect(menu.shownItem(1).active()).toBe(true);
1420
1421 menu.viewDown();
1422
1423 expect(menu.shownItem(0).active()).toBe(true);
1424 expect(menu.shownItem(0).lcField()).toEqual(' untertitel');
1425 expect(menu.shownItem(1).active()).toBe(false);
1426
1427 menu.viewDown();
1428
1429 expect(menu.shownItem(0).active()).toBe(false);
1430 expect(menu.shownItem(0).lcField()).toEqual(' veröffentlichungsdatum');
1431 expect(menu.shownItem(1).active()).toBe(false);
1432
1433 // No effect anymore
1434 menu.viewDown();
1435
1436 expect(menu.shownItem(0).active()).toBe(false);
1437 expect(menu.shownItem(0).lcField()).toEqual(' veröffentlichungsdatum');
1438 expect(menu.shownItem(1).active()).toBe(false);
1439 });
1440
1441 it('should be view upable and downable (2)', function () {
1442
1443 // List is longer than limit
1444 var menu = KorAP.OwnMenu.create(demolist);
1445 menu.limit(7);
1446
1447 // Choose the final value
1448 expect(menu.show(1)).toBe(true);
1449
1450 expect(menu.shownItem(0).active()).toBe(false);
1451 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1452 expect(menu.shownItem(1).active()).toBe(true);
1453 expect(menu.shownItem(2).active()).toBe(false);
1454 expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum');
1455 expect(menu.shownItem(4).active()).toBe(false);
1456 expect(menu.shownItem(5)).toBe(undefined);
1457
1458 // Doesn't change anything
1459 menu.viewUp();
1460
1461 expect(menu.shownItem(0).active()).toBe(false);
1462 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1463 expect(menu.shownItem(1).active()).toBe(true);
1464
1465 menu.viewDown();
1466
1467 expect(menu.shownItem(0).active()).toBe(false);
1468 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1469 expect(menu.shownItem(1).active()).toBe(true);
1470 });
1471
1472
Akronaba7a5a2016-08-15 21:58:33 +02001473 it('should scroll to a chosen value (1)', function () {
1474 var menu = KorAP.OwnMenu.create(demolist);
1475 menu.limit(3);
1476
1477 // Choose value 1
1478 expect(menu.show(1)).toBe(true);
1479
1480 expect(menu.shownItem(0).active()).toBe(false);
1481 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1482 expect(menu.shownItem(1).active()).toBe(true);
1483 expect(menu.shownItem(2).active()).toBe(false);
1484 expect(menu.shownItem(3)).toBe(undefined);
1485
1486 // Choose value 2
1487 expect(menu.show(2)).toBe(true);
1488
1489 expect(menu.shownItem(0).active()).toBe(false);
1490 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1491 expect(menu.shownItem(1).active()).toBe(false);
1492 expect(menu.shownItem(2).active()).toBe(true);
1493 expect(menu.shownItem(3)).toBe(undefined);
1494 });
1495
1496 it('should scroll to a chosen value (2)', function () {
1497 var menu = KorAP.OwnMenu.create(demolonglist);
1498
1499 // Choose value 3
1500 expect(menu.limit(3).show(3)).toBe(true);
1501 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1502 expect(menu.shownItem(0).active()).toBe(true);
1503 expect(menu.shownItem(1).active()).toBe(false);
1504 expect(menu.shownItem(2).active()).toBe(false);
1505 expect(menu.shownItem(3)).toBe(undefined);
1506 });
1507
1508 xit('should scroll to a chosen value after prefixing, if the chosen value is live');
Akron8aa1c522021-07-23 11:33:49 +02001509
1510 it('should be expendable', function () {
1511 var menu = menuClass.create([]);
1512 let entryData = 'empty';
1513 menu.readItems([
1514 ['a', '', function () { entryData = 'a' }],
1515 ['bb', '', function () { entryData = 'bb' }],
1516 ['ccc', '', function () { entryData = 'ccc' }],
1517 ]);
1518
1519 expect(menu.limit(3).show(3)).toBe(true);
1520 expect(menu.shownItem(0).lcField()).toEqual(' a');
1521 expect(menu.shownItem(1).lcField()).toEqual(' bb');
1522 expect(menu.shownItem(2).lcField()).toEqual(' ccc');
1523 expect(entryData).toEqual('empty');
1524 menu.shownItem(1).element().click();
1525 expect(entryData).toEqual('bb');
1526 expect(menu.lengthField().element().innerText).toEqual("a--bb--ccc--")
1527 expect(menu.slider().length()).toEqual(3);
1528
1529 let obj = menu.itemClass().create(
1530 ['dddd','',function () { entryData = 'dddd'} ]
1531 );
1532 menu.append(obj)
1533
1534 expect(menu.limit(2).show(1)).toBe(true);
1535 expect(menu.shownItem(0).lcField()).toEqual(' a');
1536 expect(menu.shownItem(1).lcField()).toEqual(' bb');
1537 menu.next();
1538 expect(menu.shownItem(1).lcField()).toEqual(' ccc');
1539 menu.next();
1540 expect(menu.shownItem(1).lcField()).toEqual(' dddd');
1541 menu.next();
1542 expect(menu.shownItem(0).lcField()).toEqual(' a');
1543 expect(menu.lengthField().element().innerText).toEqual("a--bb--ccc--dddd--")
1544 expect(menu.slider().length()).toEqual(4);
1545 });
Akronaba7a5a2016-08-15 21:58:33 +02001546 });
1547
1548 describe('KorAP.Prefix', function () {
1549 it('should be initializable', function () {
1550 var p = prefixClass.create();
1551 expect(p.element().classList.contains('pref')).toBeTruthy();
Akronf21bf742021-05-19 13:30:38 +02001552 expect(p.element().classList.contains('non-item')).toBeTruthy();
Akronaba7a5a2016-08-15 21:58:33 +02001553 expect(p.isSet()).not.toBeTruthy();
1554
1555 /*
1556 expect(mi.lcField()).toEqual(' baum');
1557 */
1558
1559 });
1560
1561 it('should be modifiable', function () {
1562 var p = prefixClass.create();
1563 expect(p.value()).toEqual('');
1564 expect(p.element().firstChild).toBeNull();
1565
1566 // Set string
1567 expect(p.value('Test')).toEqual('Test');
1568 expect(p.value()).toEqual('Test');
1569 expect(p.element().firstChild.nodeValue).toEqual('Test');
1570
1571 // Add string
1572 expect(p.add('ified')).toEqual('Testified');
1573 expect(p.value()).toEqual('Testified');
1574 expect(p.element().firstChild.nodeValue).toEqual('Testified');
1575
1576 // Clear string
1577 p.clear();
1578 expect(p.value()).toEqual('');
1579 expect(p.element().firstChild).toBeNull();
1580
1581 // Set string
1582 expect(p.value('Test')).toEqual('Test');
1583 expect(p.value()).toEqual('Test');
1584 expect(p.element().firstChild.nodeValue).toEqual('Test');
1585
1586 expect(p.chop()).toEqual('Tes');
1587 expect(p.value()).toEqual('Tes');
1588 expect(p.element().firstChild.nodeValue).toEqual('Tes');
1589
1590 expect(p.chop()).toEqual('Te');
1591 expect(p.value()).toEqual('Te');
1592 expect(p.element().firstChild.nodeValue).toEqual('Te');
1593
1594 expect(p.chop()).toEqual('T');
1595 expect(p.value()).toEqual('T');
1596 expect(p.element().firstChild.nodeValue).toEqual('T');
1597
1598 expect(p.chop()).toEqual('');
1599 expect(p.value()).toEqual('');
1600 expect(p.element().firstChild).toBeNull();
1601 });
1602
1603 it('should be activatable', function () {
1604 var p = prefixClass.create();
1605 expect(p.value()).toEqual('');
1606 expect(p.element().firstChild).toBeNull();
1607
1608 expect(p.value('Test')).toEqual('Test');
1609 expect(p.element().firstChild.nodeValue).toEqual('Test');
1610
1611 expect(p.active()).not.toBeTruthy();
1612 expect(p.element().classList.contains('active')).not.toBeTruthy();
1613
1614 p.active(true);
1615 expect(p.active()).toBeTruthy();
1616 expect(p.element().classList.contains('active')).toBeTruthy();
1617 });
1618 });
1619
1620 describe('KorAP.LengthField', function () {
1621 it('should be initializable', function () {
1622 var l = lengthFieldClass.create();
1623 expect(l.element().classList.contains('lengthField')).toBeTruthy();
1624 expect(l.element().children.length).toEqual(0);
1625 });
1626
1627 it('should be extensible', function () {
1628 var l = lengthFieldClass.create();
1629 l.add(['Baum']);
1630 expect(l.element().children.length).toEqual(1);
1631 expect(l.element().children[0].nodeName).toEqual('SPAN');
1632 expect(l.element().children[0].textContent).toEqual('Baum--');
1633 l.add(['Fragezeichen']);
1634 expect(l.element().children.length).toEqual(2);
1635 expect(l.element().children[1].nodeName).toEqual('SPAN');
1636 expect(l.element().children[1].textContent).toEqual('Fragezeichen--');
1637 });
1638
1639 it('should be correctly initializable', function () {
1640 var list = [
1641 ["Constituency"],
1642 ["Lemma"],
1643 ["Morphology"],
1644 ["Part-of-Speech"],
1645 ["Syntax"]
1646 ];
1647
1648 var menu = KorAP.OwnMenu.create(list);
1649
1650 expect(menu.lengthField().element().children.length).toEqual(5);
1651 });
1652 });
1653
1654 describe('KorAP.Slider', function () {
1655
1656 var demolonglist = [
1657 ['Titel', 'title'],
1658 ['Untertitel', 'subTitle'],
1659 ['Veröffentlichungsdatum', 'pubDate'],
1660 ['Länge', 'length'],
1661 ['Autor', 'author'],
1662 ['Genre', 'genre'],
1663 ['corpusID', 'corpusID'],
1664 ['docID', 'docID'],
1665 ['textID', 'textID'],
1666 ];
1667
1668 it('should correctly be initializable', function () {
1669 var list = [
1670 ["Constituency"],
1671 ["Lemma"],
1672 ["Morphology"],
1673 ["Part-of-Speech"],
1674 ["Syntax"]
1675 ];
1676
1677 var menu = KorAP.OwnMenu.create(list);
1678
1679 menu._firstActive = true;
1680 menu.limit(3);
1681
1682 expect(menu.show()).toBe(true);
1683
1684 expect(menu.shownItem(0).active()).toBe(true);
1685 expect(menu.shownItem(1).active()).toBe(false);
1686 expect(menu.shownItem(2).active()).toBe(false);
1687 expect(menu.slider().offset()).toEqual(0);
1688 expect(menu.position).toEqual(0);
1689 });
1690
1691 it('should correctly move on arrow keys', function () {
1692 var list = [
1693 ["Constituency"],
1694 ["Lemma"],
1695 ["Morphology"],
1696 ["Part-of-Speech"],
1697 ["Syntax"]
1698 ];
1699
1700 var menu = KorAP.OwnMenu.create(list);
1701
1702 menu._firstActive = true;
1703 menu.limit(3);
1704
1705 expect(menu.show()).toBe(true);
1706
1707 menu.next();
1708 expect(menu.shownItem(0).active()).toBe(false);
1709 expect(menu.shownItem(1).active()).toBe(true);
1710 expect(menu.shownItem(2).active()).toBe(false);
1711 expect(menu.slider().offset()).toEqual(0);
1712 expect(menu.position).toEqual(1);
1713
1714 menu.next();
1715 expect(menu.shownItem(0).active()).toBe(false);
1716 expect(menu.shownItem(1).active()).toBe(false);
1717 expect(menu.shownItem(2).active()).toBe(true);
1718 expect(menu.slider().offset()).toEqual(0);
1719 expect(menu.position).toEqual(2);
1720
1721 menu.next();
1722 expect(menu.shownItem(0).active()).toBe(false);
1723 expect(menu.shownItem(1).active()).toBe(false);
1724 expect(menu.shownItem(2).active()).toBe(true);
1725 expect(menu.slider().offset()).toEqual(1);
1726 expect(menu.position).toEqual(3);
1727
1728 menu.next();
1729 expect(menu.shownItem(0).active()).toBe(false);
1730 expect(menu.shownItem(1).active()).toBe(false);
1731 expect(menu.shownItem(2).active()).toBe(true);
1732 expect(menu.slider().offset()).toEqual(2);
1733 expect(menu.position).toEqual(4);
1734
1735 menu.next();
1736 expect(menu.shownItem(0).active()).toBe(true);
1737 expect(menu.shownItem(1).active()).toBe(false);
1738 expect(menu.shownItem(2).active()).toBe(false);
1739 expect(menu.slider().offset()).toEqual(0);
1740 expect(menu.position).toEqual(0);
1741
1742 expect(menu.slider()._slider.style.height).toEqual('60%');
1743 });
1744
1745 it('should correctly resize on prefixing', function () {
1746 var menu = KorAP.OwnMenu.create(demolonglist);
1747 menu._firstActive = true;
1748 menu.limit(3);
1749
1750 expect(menu.show()).toBe(true);
1751 expect(menu.slider().offset()).toEqual(0);
1752 expect(menu.slider().length()).toEqual(9);
1753
1754 expect(menu.prefix("e").show()).toBe(true);
1755 expect(menu.slider().length()).toEqual(6);
1756
1757 expect(menu.prefix("el").show()).toBe(true);
1758 expect(menu.slider().length()).toEqual(2);
1759
1760 expect(menu.prefix("e").show()).toBe(true);
1761 expect(menu.slider().length()).toEqual(6);
1762
1763 expect(menu.prefix("").show()).toBe(true);
1764 expect(menu.slider().length()).toEqual(9);
1765 });
1766
1767
1768 it('should correctly move the list on mousemove', function () {
1769 var list = [
1770 ["Constituency"],
1771 ["Lemma"],
1772 ["Morphology"],
1773 ["Part-of-Speech"],
1774 ["Syntax"]
1775 ];
1776
1777 var menu = KorAP.OwnMenu.create(list);
1778
1779 menu._firstActive = true;
1780 menu.limit(3);
1781
1782 expect(menu.show()).toBe(true);
1783
1784 expect(menu.shownItem(0).active()).toBe(true);
1785 expect(menu.shownItem(1).active()).toBe(false);
1786 expect(menu.shownItem(2).active()).toBe(false);
1787 expect(menu.slider().offset()).toEqual(0);
1788
1789 // This will normally be done on
1790 menu.slider()._rulerHeight = 100;
1791 menu.slider()._sliderHeight = 40;
1792 menu.slider()._event.initOffset = 0;
1793 expect(menu.slider().length()).toEqual(5);
1794
1795 menu.slider().movetoRel(10);
1796 expect(menu.slider().offset()).toEqual(0);
1797
1798 expect(menu.shownItem(0).active()).toBe(true);
1799 expect(menu.shownItem(0).lcField()).toEqual(' constituency');
1800 menu.slider().movetoRel(24);
1801 expect(menu.slider().offset()).toEqual(0);
1802 menu.slider().movetoRel(25);
1803 expect(menu.slider().offset()).toEqual(0);
1804
1805 menu.slider().movetoRel(30);
1806 expect(menu.slider().offset()).toEqual(1);
1807 menu.slider().movetoRel(59);
1808 expect(menu.slider().offset()).toEqual(1);
1809 expect(menu.shownItem(0).active()).toBe(false);
1810 expect(menu.shownItem(0).lcField()).toEqual(' lemma');
1811
1812 // Everything > 60 is offset 2
1813 menu.slider().movetoRel(60);
1814 expect(menu.slider().offset()).toEqual(2);
1815 menu.slider().movetoRel(180);
1816 expect(menu.slider().offset()).toEqual(2);
1817 expect(menu.shownItem(0).active()).toBe(false);
1818 expect(menu.shownItem(0).lcField()).toEqual(' morphology');
1819
1820 expect(menu.shownItem(1).active()).toBe(false);
1821 expect(menu.shownItem(2).active()).toBe(false);
1822
1823 // When the active cursor moves again - scroll to viewport
1824 // cursor is before viewport
1825 menu.next();
1826 expect(menu.shownItem(0).active()).toBe(true);
1827 expect(menu.shownItem(0).lcField()).toEqual(' lemma');
1828 expect(menu.shownItem(1).active()).toBe(false);
1829 expect(menu.shownItem(2).active()).toBe(false);
1830
1831 menu.next();
1832 menu.next();
1833 expect(menu.shownItem(0).active()).toBe(false);
1834 expect(menu.shownItem(0).lcField()).toEqual(' lemma');
1835 expect(menu.shownItem(1).active()).toBe(false);
1836 expect(menu.shownItem(1).lcField()).toEqual(' morphology');
1837 expect(menu.shownItem(2).active()).toBe(true);
1838 expect(menu.shownItem(2).lcField()).toEqual(' part-of-speech');
1839
1840 menu.slider().movetoRel(0);
1841 expect(menu.slider().offset()).toEqual(0);
1842 expect(menu.shownItem(0).active()).toBe(false);
1843 expect(menu.shownItem(0).lcField()).toEqual(' constituency');
1844 expect(menu.shownItem(1).active()).toBe(false);
1845 expect(menu.shownItem(1).lcField()).toEqual(' lemma');
1846 expect(menu.shownItem(2).active()).toBe(false);
1847 expect(menu.shownItem(2).lcField()).toEqual(' morphology');
1848
1849 // cursor is after viewport
1850 menu.next();
1851 expect(menu.slider().offset()).toEqual(2);
1852 expect(menu.shownItem(0).active()).toBe(false);
1853 expect(menu.shownItem(0).lcField()).toEqual(' morphology');
1854 expect(menu.shownItem(1).active()).toBe(false);
1855 expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech');
1856 expect(menu.shownItem(2).active()).toBe(true);
1857 expect(menu.shownItem(2).lcField()).toEqual(' syntax');
1858
1859 menu.slider().movetoRel(0);
1860 expect(menu.slider().offset()).toEqual(0);
1861 expect(menu.shownItem(0).active()).toBe(false);
1862 expect(menu.shownItem(0).lcField()).toEqual(' constituency');
1863 expect(menu.shownItem(1).active()).toBe(false);
1864 expect(menu.shownItem(1).lcField()).toEqual(' lemma');
1865 expect(menu.shownItem(2).active()).toBe(false);
1866 expect(menu.shownItem(2).lcField()).toEqual(' morphology');
1867
1868 menu.prev();
1869 expect(menu.slider().offset()).toEqual(2);
1870 expect(menu.shownItem(0).lcField()).toEqual(' morphology');
1871 expect(menu.shownItem(0).active()).toBe(false);
1872 expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech');
1873 expect(menu.shownItem(1).active()).toBe(true);
1874 expect(menu.shownItem(2).lcField()).toEqual(' syntax');
1875 expect(menu.shownItem(2).active()).toBe(false);
1876
1877 menu.prev();
1878 menu.prev();
1879 expect(menu.slider().offset()).toEqual(1);
1880 expect(menu.shownItem(0).lcField()).toEqual(' lemma');
1881 expect(menu.shownItem(0).active()).toBe(true);
1882 expect(menu.shownItem(1).lcField()).toEqual(' morphology');
1883 expect(menu.shownItem(1).active()).toBe(false);
1884 expect(menu.shownItem(2).lcField()).toEqual(' part-of-speech');
1885 expect(menu.shownItem(2).active()).toBe(false);
1886
1887 menu.slider().movetoRel(100);
1888 expect(menu.slider().offset()).toEqual(2);
1889 expect(menu.shownItem(0).lcField()).toEqual(' morphology');
1890 expect(menu.shownItem(0).active()).toBe(false);
1891 expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech');
1892 expect(menu.shownItem(1).active()).toBe(false);
1893 expect(menu.shownItem(2).lcField()).toEqual(' syntax');
1894 expect(menu.shownItem(2).active()).toBe(false);
1895
1896 menu.prev();
1897 expect(menu.slider().offset()).toEqual(0);
1898 expect(menu.shownItem(0).lcField()).toEqual(' constituency');
1899 expect(menu.shownItem(0).active()).toBe(true);
1900 expect(menu.shownItem(1).lcField()).toEqual(' lemma');
1901 expect(menu.shownItem(1).active()).toBe(false);
1902 expect(menu.shownItem(2).lcField()).toEqual(' morphology');
1903 expect(menu.shownItem(2).active()).toBe(false);
1904 });
1905 });
1906
1907 describe('KorAP.MenuBenchmark', function () {
1908 var menu = menuClass.create([
1909 ['Titel', 'title'],
1910 ['Untertitel', 'subTitle'],
1911 ['Veröffentlichungsdatum', 'pubDate'],
1912 ['Länge', 'length'],
1913 ['Autor', 'author']
1914 ]);
1915
1916 menu.limit(3).show();
1917
1918 // Some actions
1919 menu.next();
1920 menu.next();
1921 menu.prev();
1922 menu.prev();
1923 menu.prev();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001924
Akron3c2730f2016-05-24 15:08:29 +02001925 menu.pageDown();
Akron3c2730f2016-05-24 15:08:29 +02001926 menu.pageUp();
1927
Akronaba7a5a2016-08-15 21:58:33 +02001928 // There is no fourth item in the list!
1929 menu.prefix('e').show(4);
Akron5a1f5bb2016-05-23 22:00:39 +02001930 menu.next();
1931 menu.next();
Akron5a1f5bb2016-05-23 22:00:39 +02001932 menu.prev();
1933 menu.prev();
Akron5a1f5bb2016-05-23 22:00:39 +02001934 menu.prev();
Akronf86eaea2016-05-13 18:02:27 +02001935 });
1936 });