blob: c13d5e6e2f5db49b8478fa48871654fcad7c1efb [file] [log] [blame]
Akron47c086c2016-05-18 21:22:06 +02001define(['menu', 'menu/item', 'menu/prefix', 'menu/lengthField'],
2 function (menuClass, menuItemClass, prefixClass, lengthFieldClass) {
Akron1ff3ac22016-04-28 16:30:45 +02003
Nils Diewald7c8ced22015-04-15 19:21:00 +00004 // The OwnMenu item
5 KorAP.OwnMenuItem = {
6 create : function (params) {
7 return Object.create(menuItemClass).upgradeTo(KorAP.OwnMenuItem)._init(params);
8 },
9 content : function (content) {
10 if (arguments.length === 1) {
11 this._content = content;
12 };
13 return this._content;
14 },
15 _init : function (params) {
16 if (params[0] === undefined)
17 throw new Error("Missing parameters");
18
19 this._content = document.createTextNode(params[0]);
20 this._lcField = ' ' + this.content().textContent.toLowerCase();
21
22 return this;
23 }
24 };
25
26 // The OwnMenu
27 KorAP.OwnMenu = {
Akron7524be12016-06-01 17:31:33 +020028 create : function (list) {
Nils Diewald7c8ced22015-04-15 19:21:00 +000029 return Object.create(menuClass)
30 .upgradeTo(KorAP.OwnMenu)
Akron7524be12016-06-01 17:31:33 +020031 ._init(list, { itemClass : KorAP.OwnMenuItem });
Nils Diewald7c8ced22015-04-15 19:21:00 +000032 }
33 };
Nils Diewaldfda29d92015-01-22 17:28:01 +000034
Nils Diewaldfda29d92015-01-22 17:28:01 +000035
Nils Diewald7c8ced22015-04-15 19:21:00 +000036 // HintMenuItem
37 KorAP.HintMenuItem = {
38 create : function (params) {
39 return Object.create(menuItemClass)
40 .upgradeTo(KorAP.HintMenuItem)
41 ._init(params);
42 },
43 content : function (content) {
44 if (arguments.length === 1) {
45 this._content = content;
46 };
47 return this._content;
48 },
49 _init : function (params) {
50 if (params[0] === undefined || params[1] === undefined)
51 throw new Error("Missing parameters");
52
53 this._name = params[0];
54 this._action = params[1];
55 this._lcField = ' ' + this._name.toLowerCase();
56
57 if (params.length > 2) {
58 this._desc = params[2];
59 this._lcField += " " + this._desc.toLowerCase();
60 };
61
62 return this;
63 },
64
65 name : function () {
66 return this._name;
67 },
68 action : function () {
69 return this._action;
70 },
71 desc : function () {
72 return this._desc;
73 },
74 element : function () {
75 // already defined
76 if (this._element !== undefined)
77 return this._element;
78
79 // Create list item
80 var li = document.createElement("li");
81 li.setAttribute("data-action", this._action);
82
83 // Create title
84 var name = document.createElement("strong");
85 name.appendChild(document.createTextNode(this._name));
86
87 li.appendChild(name);
88
89 // Create description
90 if (this._desc !== undefined) {
91 var desc = document.createElement("span");
92 desc.appendChild(document.createTextNode(this._desc));
93 li.appendChild(desc);
94 };
95 return this._element = li;
96 }
97 };
Nils Diewald86dad5b2015-01-28 15:09:07 +000098
99
Nils Diewald7c8ced22015-04-15 19:21:00 +0000100 // HintMenu
101 KorAP.HintMenu = {
Akron7524be12016-06-01 17:31:33 +0200102 create : function (context, list) {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000103 var obj = Object.create(menuClass)
104 .upgradeTo(KorAP.HintMenu)
Akron7524be12016-06-01 17:31:33 +0200105 ._init(list, {itemClass : KorAP.HintMenuItem});
Nils Diewald7c8ced22015-04-15 19:21:00 +0000106 obj._context = context;
107 return obj;
108 }
109 };
Nils Diewald86dad5b2015-01-28 15:09:07 +0000110
111
Nils Diewald7c8ced22015-04-15 19:21:00 +0000112 // The ComplexMenuItem
113 KorAP.ComplexMenuItem = {
114 create : function (params) {
115 return Object.create(menuItemClass)
116 .upgradeTo(KorAP.ComplexMenuItem)
117 ._init(params);
118 },
119 content : function (content) {
120 if (arguments.length === 1) {
121 this._content = content;
122 };
123 return this._content;
124 },
125 _init : function (params) {
126 if (params[0] === undefined)
127 throw new Error("Missing parameters");
128
129 var r = document.createElement('div');
130 for (var i = 1; i <= params.length; i++) {
131 var h = document.createElement('h' + i);
132 h.appendChild(document.createTextNode(params[i-1]));
133 r.appendChild(h);
134 };
135
136 this._content = r;
137 this._lcField = ' ' + this.content().textContent.toLowerCase();
138
139 return this;
140 }
141 };
Nils Diewald2fe12e12015-03-06 16:47:06 +0000142
143
Nils Diewald7c8ced22015-04-15 19:21:00 +0000144 describe('KorAP.MenuItem', function () {
145 it('should be initializable', function () {
146 expect(
147 function() { menuItemClass.create([]) }
148 ).toThrow(new Error("Missing parameters"));
Nils Diewald2fe12e12015-03-06 16:47:06 +0000149
Nils Diewald7c8ced22015-04-15 19:21:00 +0000150 expect(
151 function() { KorAP.OwnMenuItem.create([]) }
152 ).toThrow(new Error("Missing parameters"));
Nils Diewald2fe12e12015-03-06 16:47:06 +0000153
Nils Diewald7c8ced22015-04-15 19:21:00 +0000154 var mi = KorAP.OwnMenuItem.create(["Baum"]);
155 expect(mi.element().firstChild.nodeValue).toEqual('Baum');
156 expect(mi.lcField()).toEqual(' baum');
157 });
Nils Diewald2fe12e12015-03-06 16:47:06 +0000158
Nils Diewald7c8ced22015-04-15 19:21:00 +0000159 it('shouldn\'t have a reference to the menu', function () {
160 var menuItem = KorAP.OwnMenuItem.create(['Test']);
161 expect(menuItem.menu()).toBe(undefined);
162 });
163
164 it('should be activatable and deactivateable by class', function () {
165 var menuItem = KorAP.OwnMenuItem.create(['Test']);
166
167 expect(menuItem.active()).toBe(false);
168 expect(menuItem.element().getAttribute("class")).toBe(null);
169 menuItem.active(true);
170 expect(menuItem.active()).toBe(true);
171 expect(menuItem.element().getAttribute("class")).toEqual("active");
172 menuItem.active(false); // Is active
173 expect(menuItem.active()).toBe(false);
174 expect(menuItem.element().getAttribute("class")).toEqual("");
175 menuItem.active(true);
176 expect(menuItem.active()).toBe(true);
177 expect(menuItem.element().getAttribute("class")).toEqual("active");
178
179 menuItem = KorAP.OwnMenuItem.create(['Spiegel']);
180 expect(menuItem.active()).toBe(false);
181 expect(menuItem.element().getAttribute("class")).toBe(null);
182 menuItem.active(false); // Is not active
183 expect(menuItem.active()).toBe(false);
184 expect(menuItem.element().getAttribute("class")).toBe(null);
185 });
186
187 it('should be set to boundary', function () {
188 var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']);
189 expect(menuItem.active()).toBe(false);
190 expect(menuItem.element().getAttribute("class")).toBe(null);
191
192 // Set active
193 menuItem.active(true);
194 expect(menuItem.active()).toBe(true);
195 expect(menuItem.noMore()).toBe(false);
196 expect(menuItem.element().getAttribute("class")).toEqual("active");
197
198 // Set no more
199 menuItem.noMore(true);
200 expect(menuItem.active()).toBe(true);
201 expect(menuItem.noMore()).toBe(true);
202 expect(menuItem.element().getAttribute("class")).toEqual("active no-more");
203
204 // No no more
205 menuItem.noMore(false);
206 expect(menuItem.active()).toBe(true);
207 expect(menuItem.noMore()).toBe(false);
208 expect(menuItem.element().getAttribute("class")).toEqual("active");
209
210 // Set no more, deactivate
211 menuItem.noMore(true);
212 menuItem.active(false);
213 expect(menuItem.active()).toBe(false);
214 expect(menuItem.noMore()).toBe(true);
215 expect(menuItem.element().getAttribute("class")).toEqual("no-more");
216
217 // Set active
218 menuItem.active(true);
219 expect(menuItem.active()).toBe(true);
220 expect(menuItem.noMore()).toBe(true);
221 expect(menuItem.element().getAttribute("class")).toEqual("no-more active");
222 });
Nils Diewald2fe12e12015-03-06 16:47:06 +0000223
224
Nils Diewald7c8ced22015-04-15 19:21:00 +0000225 it('should be highlightable', function () {
226 // Highlight in the middle
227 var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']);
228 menuItem.highlight("ren");
229 expect(menuItem.element().innerHTML).toEqual("Co<mark>reN</mark>LP");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000230
Nils Diewald7c8ced22015-04-15 19:21:00 +0000231 menuItem.lowlight();
232 expect(menuItem.element().innerHTML).toEqual("CoreNLP");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000233
Nils Diewald7c8ced22015-04-15 19:21:00 +0000234 var plain = "<div><h1>CoreNLP</h1><h2>corenlp/</h2></div>";
Nils Diewaldfda29d92015-01-22 17:28:01 +0000235
Nils Diewald7c8ced22015-04-15 19:21:00 +0000236 // Starting highlight
237 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
238 menuItem.highlight("cor");
239 expect(menuItem.element().innerHTML).toEqual("<div><h1><mark>Cor</mark>eNLP</h1><h2><mark>cor</mark>enlp/</h2></div>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000240
Nils Diewald7c8ced22015-04-15 19:21:00 +0000241 menuItem.lowlight();
242 expect(menuItem.element().innerHTML).toEqual(plain);
Nils Diewald6e43ffd2015-03-25 18:55:39 +0000243
Nils Diewald7c8ced22015-04-15 19:21:00 +0000244 // Starting highlight - short
245 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
246 menuItem.highlight("c");
247 expect(menuItem.element().innerHTML).toEqual("<div><h1><mark>C</mark>oreNLP</h1><h2><mark>c</mark>orenlp/</h2></div>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000248
Nils Diewald7c8ced22015-04-15 19:21:00 +0000249 menuItem.lowlight();
250 expect(menuItem.element().innerHTML).toEqual(plain);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000251
Nils Diewald7c8ced22015-04-15 19:21:00 +0000252 // Highlight at the end
253 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
254 menuItem.highlight("nlp");
255 expect(menuItem.element().innerHTML).toEqual("<div><h1>Core<mark>NLP</mark></h1><h2>core<mark>nlp</mark>/</h2></div>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000256
Nils Diewald7c8ced22015-04-15 19:21:00 +0000257 menuItem.lowlight();
258 expect(menuItem.element().innerHTML).toEqual(plain);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000259
Nils Diewald7c8ced22015-04-15 19:21:00 +0000260 // Highlight at the end - short
261 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
262 menuItem.highlight("p");
263 expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNL<mark>P</mark></h1><h2>corenl<mark>p</mark>/</h2></div>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000264
Nils Diewald7c8ced22015-04-15 19:21:00 +0000265 menuItem.lowlight();
266 expect(menuItem.element().innerHTML).toEqual(plain);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000267
Nils Diewald7c8ced22015-04-15 19:21:00 +0000268 // No highlight
269 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
270 menuItem.highlight("xp");
271 expect(menuItem.element().innerHTML).toEqual(plain);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000272
Nils Diewald7c8ced22015-04-15 19:21:00 +0000273 menuItem.lowlight();
274 expect(menuItem.element().innerHTML).toEqual(plain);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000275
Nils Diewald7c8ced22015-04-15 19:21:00 +0000276 // Highlight in the middle - first
277 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
278 menuItem.highlight("ren");
279 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>");
280
281 plain = "<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Example</h3></div>"
282
283 menuItem.lowlight();
284 expect(menuItem.element().innerHTML).toEqual(plain);
285
286 // Highlight in the middle - second
287 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
288 menuItem.highlight("ampl");
289 expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Ex<mark>ampl</mark>e</h3></div>");
290
291 menuItem.lowlight();
292 expect(menuItem.element().innerHTML).toEqual(plain);
293
294 // Highlight in the middle - both
295 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
296 menuItem.highlight("e");
297 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>");
298
299 menuItem.lowlight();
300 expect(menuItem.element().innerHTML).toEqual(plain);
301
302 // Highlight in the end - second
303 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
304 menuItem.highlight("le");
305 expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Examp<mark>le</mark></h3></div>");
306
307 menuItem.lowlight();
308 expect(menuItem.element().innerHTML).toEqual(plain);
309
310 // Highlight at the beginning - second
311 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
312 menuItem.highlight("this");
313 expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3><mark>This</mark> is my Example</h3></div>");
314
315 menuItem.lowlight();
316 expect(menuItem.element().innerHTML).toEqual(plain);
317 });
Nils Diewaldfda29d92015-01-22 17:28:01 +0000318 });
319
320
Nils Diewald7c8ced22015-04-15 19:21:00 +0000321 describe('KorAP.Menu', function () {
Nils Diewald86dad5b2015-01-28 15:09:07 +0000322 var list = [
Nils Diewald7c8ced22015-04-15 19:21:00 +0000323 ["Constituency", "c=", "Example 1"],
324 ["Lemma", "l="],
325 ["Morphology", "m=", "Example 2"],
326 ["Part-of-Speech", "p="],
327 ["Syntax", "syn="]
Nils Diewald86dad5b2015-01-28 15:09:07 +0000328 ];
Nils Diewaldfda29d92015-01-22 17:28:01 +0000329
Nils Diewald7c8ced22015-04-15 19:21:00 +0000330 var demolist = [
331 ['Titel', 'title'],
332 ['Untertitel', 'subTitle'],
333 ['Veröffentlichungsdatum', 'pubDate'],
334 ['Länge', 'length'],
335 ['Autor', 'author']
336 ];
Nils Diewaldfda29d92015-01-22 17:28:01 +0000337
Nils Diewald7c8ced22015-04-15 19:21:00 +0000338 var demolonglist = [
339 ['Titel', 'title'],
340 ['Untertitel', 'subTitle'],
341 ['Veröffentlichungsdatum', 'pubDate'],
342 ['Länge', 'length'],
343 ['Autor', 'author'],
344 ['Genre', 'genre'],
345 ['corpusID', 'corpusID'],
346 ['docID', 'docID'],
347 ['textID', 'textID'],
348 ];
Nils Diewald86dad5b2015-01-28 15:09:07 +0000349
Nils Diewald7c8ced22015-04-15 19:21:00 +0000350 it('should be initializable', function () {
351 var list = [
352 ["Constituency"],
353 ["Lemma"],
354 ["Morphology"],
355 ["Part-of-Speech"],
356 ["Syntax"]
357 ];
Nils Diewaldfda29d92015-01-22 17:28:01 +0000358
Nils Diewald7c8ced22015-04-15 19:21:00 +0000359 var menu = KorAP.OwnMenu.create(list);
Akronc1457bf2015-06-11 19:24:00 +0200360 menu._firstActive = true;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000361 expect(menu.itemClass()).toEqual(KorAP.OwnMenuItem);
362 expect(menu.element().nodeName).toEqual('UL');
Akronf0c31ed2016-06-11 11:27:01 +0200363 expect(menu.element().classList.contains('visible')).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000364 expect(menu.limit()).toEqual(8);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000365
Nils Diewald7c8ced22015-04-15 19:21:00 +0000366 menu.limit(9);
367 expect(menu.limit()).toEqual(9);
Nils Diewald86dad5b2015-01-28 15:09:07 +0000368
Nils Diewald7c8ced22015-04-15 19:21:00 +0000369 menu.limit(8);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000370
Nils Diewald7c8ced22015-04-15 19:21:00 +0000371 // view
372 menu.show();
373
374 // First element in list
375 expect(menu.item(0).active()).toBe(true);
376 expect(menu.item(0).noMore()).toBe(true);
377
378 // Middle element in list
379 expect(menu.item(2).active()).toBe(false);
380 expect(menu.item(2).noMore()).toBe(false);
381
382 // Last element in list
383 expect(menu.item(menu.length() - 1).active()).toBe(false);
384 expect(menu.item(menu.length() - 1).noMore()).toBe(true);
385 });
386
387 it('should have a reference to the menu', function () {
388 var menu = KorAP.HintMenu.create("cnx/", list);
389 expect(menu.item(0).menu()).toEqual(menu);
390
391 menu = KorAP.HintMenu.create("cnx/", list);
392 expect(menu.element().menu).toEqual(menu);
393 });
394
395
396 it('should be visible', function () {
397 var menu = KorAP.HintMenu.create("cnx/", list);
Akrona92fd8d2016-05-24 21:13:41 +0200398 expect(menu.removeItems()).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000399 menu.limit(3);
400
401 expect(menu.show()).toBe(true);
402
Akronf86eaea2016-05-13 18:02:27 +0200403 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
404 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>");
405 expect(menu.element().childNodes[4].getAttribute("data-action")).toEqual("l=");
406 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
407 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000408
409 // Check boundaries
Akronf86eaea2016-05-13 18:02:27 +0200410 expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(true);
Akronc7448732016-04-27 14:06:58 +0200411 expect(menu.element().childNodes[4].classList.contains("no-more")).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200412 expect(menu.element().childNodes[5].classList.contains("no-more")).toBe(false);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000413 });
414
415 it('should be filterable', function () {
416 var menu = KorAP.HintMenu.create("cnx/", list);
417 menu.limit(3);
418 expect(menu.prefix("o").show()).toBe(true);
419 expect(menu.element().childNodes[0].innerHTML).toEqual("o");
Akronf86eaea2016-05-13 18:02:27 +0200420 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
421 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
422 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
423 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000424
425 // Check boundaries
Akronf86eaea2016-05-13 18:02:27 +0200426 expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(true);
427 expect(menu.element().childNodes[4].classList.contains("no-more")).toBe(false);
428 expect(menu.element().childNodes[5].classList.contains("no-more")).toBe(true);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000429
430 menu.limit(2);
431
432 expect(menu.prefix("o").show()).toBe(true);
433 expect(menu.element().childNodes[0].innerHTML).toEqual("o");
Akronf86eaea2016-05-13 18:02:27 +0200434 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
435 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
436 expect(menu.element().childNodes[5]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000437
438 // Check boundaries
Akronf86eaea2016-05-13 18:02:27 +0200439 expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(true);
440 expect(menu.element().childNodes[4].classList.contains("no-more")).toBe(false);
441 expect(menu.element().childNodes[5]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000442
443 expect(menu.prefix("e").show()).toBe(true);
444 expect(menu.element().childNodes[0].innerHTML).toEqual("e");
Akronf86eaea2016-05-13 18:02:27 +0200445 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
446 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
447 expect(menu.element().childNodes[5]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000448
449 menu.limit(5);
450 expect(menu.prefix("a").show()).toBe(true);
451 expect(menu.element().childNodes[0].innerHTML).toEqual("a");
Akronf86eaea2016-05-13 18:02:27 +0200452 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Ex<mark>a</mark>mple 1</span>");
453 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemm<mark>a</mark></strong>");
454 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Ex<mark>a</mark>mple 2</span>");
455 expect(menu.element().childNodes[6].innerHTML).toEqual("<strong>P<mark>a</mark>rt-of-Speech</strong>");
456 expect(menu.element().childNodes[7].innerHTML).toEqual("<strong>Synt<mark>a</mark>x</strong>");
457 expect(menu.element().childNodes[8]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000458 });
459
460
461 it('should be nextable', function () {
462 var menu = KorAP.HintMenu.create("cnx/", list);
Akronc1457bf2015-06-11 19:24:00 +0200463 menu._firstActive = true;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000464
465 // Show only 3 items
466 menu.limit(3);
467 expect(menu.show()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +0200468 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000469 expect(menu.shownItem(0).active()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +0200470 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000471 expect(menu.shownItem(1).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200472 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000473 expect(menu.shownItem(2).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200474 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000475
476 // Activate next (1)
477 menu.next();
Akronf86eaea2016-05-13 18:02:27 +0200478 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000479 expect(menu.shownItem(0).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200480 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000481 expect(menu.shownItem(1).active()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +0200482 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000483 expect(menu.shownItem(2).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200484 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000485
486 // Activate next (2)
487 menu.next();
Akronf86eaea2016-05-13 18:02:27 +0200488 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000489 expect(menu.shownItem(0).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200490 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000491 expect(menu.shownItem(1).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200492 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000493 expect(menu.shownItem(2).active()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +0200494 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000495
496 // Activate next (3)
497 // scroll!
498 menu.next();
Akronf86eaea2016-05-13 18:02:27 +0200499 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000500 expect(menu.shownItem(0).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200501 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000502 expect(menu.shownItem(1).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200503 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000504 expect(menu.shownItem(2).active()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +0200505 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000506
507 // Activate next (4)
508 menu.next();
Akronf86eaea2016-05-13 18:02:27 +0200509 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000510 expect(menu.shownItem(0).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200511 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000512 expect(menu.shownItem(1).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200513 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Syntax</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000514 expect(menu.shownItem(2).active()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +0200515 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000516
517 // Activate next (5) - ROLL
518 menu.next();
Akronf86eaea2016-05-13 18:02:27 +0200519 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000520 expect(menu.shownItem(0).active()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +0200521 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000522 expect(menu.shownItem(1).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200523 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000524 expect(menu.shownItem(2).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200525 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000526
527 // Active next (6)
528 menu.next();
Akronf86eaea2016-05-13 18:02:27 +0200529 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000530 expect(menu.shownItem(0).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200531 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000532 expect(menu.shownItem(1).active()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +0200533 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000534 expect(menu.shownItem(2).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200535 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000536 });
537
Akron9c4d1ae2016-05-25 21:43:22 +0200538 it('should be nextable without active field', function () {
539 var menu = KorAP.HintMenu.create("cnx/", list);
540 menu.limit(3);
541 expect(menu.show()).toBe(true);
542 menu.next();
543 expect(menu.shownItem(0).active()).toEqual(true);
544 });
545
546
Nils Diewald7c8ced22015-04-15 19:21:00 +0000547 it('should be prevable', function () {
548 var menu = KorAP.HintMenu.create("cnx/", list);
Akronc1457bf2015-06-11 19:24:00 +0200549 menu._firstActive = true;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000550 menu.limit(3);
551 expect(menu.show()).toBe(true);
552
Akronf86eaea2016-05-13 18:02:27 +0200553 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000554 expect(menu.shownItem(0).active()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +0200555 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000556 expect(menu.shownItem(1).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200557 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000558 expect(menu.shownItem(2).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200559 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000560
561 // Activate prev (1) - roll to bottom
562 menu.prev();
Akronf86eaea2016-05-13 18:02:27 +0200563 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000564 expect(menu.shownItem(0).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200565 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000566 expect(menu.shownItem(1).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200567 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Syntax</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000568 expect(menu.shownItem(2).active()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +0200569 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000570
571 // Activate prev (2)
572 menu.prev();
Akronf86eaea2016-05-13 18:02:27 +0200573 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000574 expect(menu.shownItem(0).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200575 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000576 expect(menu.shownItem(1).active()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +0200577 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Syntax</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000578 expect(menu.shownItem(2).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200579 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000580
581 // Activate prev (3)
582 menu.prev();
583 expect(menu.shownItem(0).name()).toEqual("Morphology");
584 expect(menu.shownItem(0).active()).toBe(true);
585 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
586 expect(menu.shownItem(1).active()).toBe(false);
587 expect(menu.shownItem(2).name()).toEqual("Syntax");
588 expect(menu.shownItem(2).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200589 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000590
591 // Activate prev (4)
592 menu.prev();
593 expect(menu.shownItem(0).name()).toEqual("Lemma");
594 expect(menu.shownItem(0).active()).toBe(true);
595 expect(menu.shownItem(1).name()).toEqual("Morphology");
596 expect(menu.shownItem(1).active()).toBe(false);
597 expect(menu.shownItem(2).name()).toEqual("Part-of-Speech");
598 expect(menu.shownItem(2).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200599 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000600
601 // Activate prev (5)
602 menu.prev();
603 expect(menu.shownItem(0).name()).toEqual("Constituency");
604 expect(menu.shownItem(0).active()).toBe(true);
605 expect(menu.shownItem(1).name()).toEqual("Lemma");
606 expect(menu.shownItem(1).active()).toBe(false);
607 expect(menu.shownItem(2).name()).toEqual("Morphology");
608 expect(menu.shownItem(2).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200609 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000610
611 // Activate next (1)
612 menu.next();
613 expect(menu.shownItem(0).name()).toEqual("Constituency");
614 expect(menu.shownItem(0).active()).toBe(false);
615 expect(menu.shownItem(1).name()).toEqual("Lemma");
616 expect(menu.shownItem(1).active()).toBe(true);
617 expect(menu.shownItem(2).name()).toEqual("Morphology");
618 expect(menu.shownItem(2).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200619 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000620
621 // Activate prev (6)
622 menu.prev();
623
624 // Activate prev (7)
625 menu.prev();
626 expect(menu.shownItem(0).name()).toEqual("Morphology");
627 expect(menu.shownItem(0).active()).toBe(false);
628 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
629 expect(menu.shownItem(1).active()).toBe(false);
630 expect(menu.shownItem(2).name()).toEqual("Syntax");
631 expect(menu.shownItem(2).active()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +0200632 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000633 });
634
Akron9c4d1ae2016-05-25 21:43:22 +0200635 it('should be prevable without active field', function () {
636 var menu = KorAP.HintMenu.create("cnx/", list);
637 menu.limit(3);
638 expect(menu.show()).toBe(true);
639 menu.prev();
640 expect(menu.shownItem(2).active()).toEqual(true);
641 expect(menu.shownItem(2).lcField()).toEqual(' syntax');
642 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000643
644 it('should be navigatable and filterable (prefix = "o")', function () {
645 var menu = KorAP.HintMenu.create("cnx/", list);
Akronc1457bf2015-06-11 19:24:00 +0200646 menu._firstActive = true;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000647 menu.limit(2);
648
649 expect(menu.prefix("o").show()).toBe(true);
650 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200651 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000652 expect(menu.shownItem(0).active()).toBe(true);
653 expect(menu.shownItem(1).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200654 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000655 expect(menu.shownItem(1).active()).toBe(false);
656 expect(menu.shownItem(2)).toBe(undefined);
657
658 // Next (1)
659 menu.next();
660 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200661 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000662 expect(menu.shownItem(0).active()).toBe(false);
663 expect(menu.shownItem(1).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200664 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000665 expect(menu.shownItem(1).active()).toBe(true);
666 expect(menu.shownItem(2)).toBe(undefined);
667
668 // Next (2)
669 menu.next();
670 expect(menu.shownItem(0).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200671 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000672 expect(menu.shownItem(0).active()).toBe(false);
673 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
Akronf86eaea2016-05-13 18:02:27 +0200674 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000675 expect(menu.shownItem(1).active()).toBe(true);
676 expect(menu.shownItem(2)).toBe(undefined);
677
678 // Next (3) - to prefix
679 menu.next();
680 expect(menu.shownItem(0).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200681 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000682 expect(menu.shownItem(0).active()).toBe(false);
683 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
Akronf86eaea2016-05-13 18:02:27 +0200684 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000685 expect(menu.shownItem(1).active()).toBe(false);
686 expect(menu.shownItem(2)).toBe(undefined);
687
688 menu.next();
689 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200690 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000691 expect(menu.shownItem(0).active()).toBe(true);
692 expect(menu.shownItem(1).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200693 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000694 expect(menu.shownItem(1).active()).toBe(false);
695 expect(menu.shownItem(2)).toBe(undefined);
696 });
697
698
699 it('should be navigatable and filterable (prefix = "ex", "e")', function () {
700 var menu = KorAP.HintMenu.create("cnx/", list);
Akronc1457bf2015-06-11 19:24:00 +0200701 menu._firstActive = true;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000702
703 menu.limit(2);
704 expect(menu.prefix("ex").show()).toBe(true);
705
706 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200707 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000708 expect(menu.shownItem(0).active()).toBe(true);
709 expect(menu.shownItem(1).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200710 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000711 expect(menu.shownItem(1).active()).toBe(false);
712 expect(menu.shownItem(2)).toBe(undefined);
713
714 // Next (1)
715 menu.next();
716 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200717 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000718 expect(menu.shownItem(0).active()).toBe(false);
719 expect(menu.shownItem(1).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200720 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000721 expect(menu.shownItem(1).active()).toBe(true);
722 expect(menu.shownItem(2)).toBe(undefined);
723
724 // Next (2)
725 menu.next();
726
727 expect(menu.prefix()).toEqual('ex');
728 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200729 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000730 expect(menu.shownItem(0).active()).toBe(false);
731
732 expect(menu.shownItem(1).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200733 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000734 expect(menu.shownItem(1).active()).toBe(false);
735 expect(menu.shownItem(2)).toBe(undefined);
736
737 // Reset limit
738 menu.limit(5);
739
740 // Change show
741 expect(menu.prefix("e").show()).toBe(true);
742 expect(menu._prefix.active()).toBe(false);
743 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200744 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000745 expect(menu.shownItem(0).active()).toBe(true);
746 expect(menu.shownItem(1).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200747 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000748 expect(menu.shownItem(1).active()).toBe(false);
749 expect(menu.shownItem(2)).toBe(undefined);
750
751 // Next (1)
752 menu.next();
753 expect(menu._prefix.active()).toBe(false);
754 expect(menu.prefix()).toEqual('e');
755 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200756 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000757 expect(menu.shownItem(0).active()).toBe(false);
758 expect(menu.shownItem(1).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200759 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000760 expect(menu.shownItem(1).active()).toBe(true);
761 expect(menu.shownItem(2)).toBe(undefined);
762
763 // Next (2)
764 menu.next();
765 expect(menu._prefix.active()).toBe(true);
766 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200767 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000768 expect(menu.shownItem(0).active()).toBe(false);
769 expect(menu.shownItem(1).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200770 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000771 expect(menu.shownItem(1).active()).toBe(false);
772 expect(menu.shownItem(2)).toBe(undefined);
773
774 // Next (3)
775 menu.next();
776 expect(menu._prefix.active()).toBe(false);
777 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200778 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000779 expect(menu.shownItem(0).active()).toBe(true);
780 expect(menu.shownItem(1).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200781 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000782 expect(menu.shownItem(1).active()).toBe(false);
783 expect(menu.shownItem(2)).toBe(undefined);
784 });
785
786
Akrona92fd8d2016-05-24 21:13:41 +0200787 it('should choose prefix with failing prefix (1)', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000788 var menu = KorAP.HintMenu.create("cnx/", list);
789 menu.limit(2);
Akron6ed13992016-05-23 18:06:05 +0200790 expect(menu.prefix("exit").show()).toBe(true);
Akrona92fd8d2016-05-24 21:13:41 +0200791 expect(menu.element().querySelector('li')).toBe(null);
792 expect(menu.shownItem(0)).toBeUndefined();
793 expect(menu._prefix.active()).toBe(true);
794 });
795
796
797 it('should choose prefix with failing prefix (2)', function () {
798 var menu = KorAP.HintMenu.create("cnx/", list);
799 menu.limit(2);
800 expect(menu.show()).toBe(true);
801 expect(menu.prefix("exit").show()).toBe(true);
802 expect(menu.element().querySelector('li')).toBe(null);
Akron6ed13992016-05-23 18:06:05 +0200803 expect(menu.shownItem(0)).toBeUndefined();
804 expect(menu._prefix.active()).toBe(true);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000805 });
806
Akronb38afb22016-05-25 19:30:01 +0200807 it('should ignore navigation with failing prefix', function () {
808 var menu = KorAP.HintMenu.create("cnx/", list);
809 menu.limit(2);
810 expect(menu.show()).toBe(true);
811
812 menu.next();
813
814 expect(menu.prefix("exit").show()).toBe(true);
815 expect(menu.element().querySelector('li')).toBe(null);
816 expect(menu.shownItem(0)).toBeUndefined();
817 expect(menu._prefix.active()).toBe(true);
818
819 menu.next();
820 expect(menu._prefix.active()).toBe(true);
821
822 menu.prev();
823 expect(menu._prefix.active()).toBe(true);
824
825 });
Akron37513a62015-11-17 01:07:11 +0100826
Nils Diewald7c8ced22015-04-15 19:21:00 +0000827 it('should be navigatable with prefix', function () {
828 var menu = KorAP.HintMenu.create("cnx/", demolist);
Akronc1457bf2015-06-11 19:24:00 +0200829 menu._firstActive = true;
830
Nils Diewald7c8ced22015-04-15 19:21:00 +0000831 menu.limit(3);
832
833 expect(menu.show()).toBe(true);
834 expect(menu.prefix()).toEqual("");
835
836 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200837 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000838 expect(menu.shownItem(0).active()).toBe(true);
839 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200840 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000841 expect(menu.shownItem(1).active()).toBe(false);
842 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200843 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000844 expect(menu.shownItem(2).active()).toBe(false);
845 expect(menu.shownItem(3)).toBe(undefined);
846
847 menu._prefix.add('a');
848 expect(menu.show()).toBe(true);
849 expect(menu.prefix()).toEqual("a");
850 expect(menu.shownItem(0).name()).toEqual("Autor");
Akronf86eaea2016-05-13 18:02:27 +0200851 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000852
853 menu._prefix.add('u');
854 expect(menu.show()).toBe(true);
855 expect(menu.prefix()).toEqual("au");
856 expect(menu.shownItem(0).name()).toEqual("Autor");
Akronf86eaea2016-05-13 18:02:27 +0200857 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong><mark>Au</mark>tor</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000858
Nils Diewald7148c6f2015-05-04 15:07:53 +0000859 menu._prefix.chop();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000860 expect(menu.show()).toBe(true);
861 expect(menu.prefix()).toEqual("a");
862 expect(menu.shownItem(0).name()).toEqual("Autor");
Akronf86eaea2016-05-13 18:02:27 +0200863 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000864
Nils Diewald7148c6f2015-05-04 15:07:53 +0000865 menu._prefix.chop();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000866 expect(menu.show()).toBe(true);
867 expect(menu.prefix()).toEqual("");
868 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200869 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000870 expect(menu.shownItem(0).active()).toBe(true);
871 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200872 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000873 expect(menu.shownItem(1).active()).toBe(false);
874 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200875 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000876 expect(menu.shownItem(2).active()).toBe(false);
877 expect(menu.shownItem(3)).toBe(undefined);
878
879 // Forward
Nils Diewald7148c6f2015-05-04 15:07:53 +0000880 menu._prefix.chop();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000881 expect(menu.show()).toBe(true);
882 expect(menu.prefix()).toEqual("");
883 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200884 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000885 expect(menu.shownItem(0).active()).toBe(true);
886 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200887 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000888 expect(menu.shownItem(1).active()).toBe(false);
889 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200890 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000891 expect(menu.shownItem(2).active()).toBe(false);
892
893 // Forward
894 menu.next();
895 expect(menu.prefix()).toEqual("");
896 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200897 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000898 expect(menu.shownItem(0).active()).toBe(false);
899 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200900 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000901 expect(menu.shownItem(1).active()).toBe(true);
902 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200903 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000904 expect(menu.shownItem(2).active()).toBe(false);
905 expect(menu.shownItem(3)).toBe(undefined);
906
907 // Forward
908 menu.next();
909 expect(menu.prefix()).toEqual("");
910 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200911 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000912 expect(menu.shownItem(0).active()).toBe(false);
913 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200914 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000915 expect(menu.shownItem(1).active()).toBe(false);
916 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200917 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000918 expect(menu.shownItem(2).active()).toBe(true);
919 expect(menu.shownItem(3)).toBe(undefined);
920
921 // Forward
922 menu.next();
923 expect(menu.prefix()).toEqual("");
924 expect(menu.shownItem(0).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200925 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Untertitel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000926 expect(menu.shownItem(0).active()).toBe(false);
927 expect(menu.shownItem(1).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200928 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000929 expect(menu.shownItem(1).active()).toBe(false);
930 expect(menu.shownItem(2).name()).toEqual("Länge");
Akronf86eaea2016-05-13 18:02:27 +0200931 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Länge</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000932 expect(menu.shownItem(2).active()).toBe(true);
933 expect(menu.shownItem(3)).toBe(undefined);
934
935 // Forward
936 menu.next();
937 expect(menu.prefix()).toEqual("");
938 expect(menu.shownItem(0).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200939 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000940 expect(menu.shownItem(0).active()).toBe(false);
941 expect(menu.shownItem(1).name()).toEqual("Länge");
Akronf86eaea2016-05-13 18:02:27 +0200942 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Länge</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000943 expect(menu.shownItem(1).active()).toBe(false);
944 expect(menu.shownItem(2).name()).toEqual("Autor");
Akronf86eaea2016-05-13 18:02:27 +0200945 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Autor</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000946 expect(menu.shownItem(2).active()).toBe(true);
947 expect(menu.shownItem(3)).toBe(undefined);
948
949 // Forward
950 menu.next();
951 expect(menu.prefix()).toEqual("");
952 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200953 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000954 expect(menu.shownItem(0).active()).toBe(true);
955 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200956 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000957 expect(menu.shownItem(1).active()).toBe(false);
958 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200959 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000960 expect(menu.shownItem(2).active()).toBe(false);
961 });
962
963
964 it('should be navigatable with a prefix (1)', function () {
965 var menu = KorAP.HintMenu.create("cnx/", demolist);
Akronc1457bf2015-06-11 19:24:00 +0200966 menu._firstActive = true;
967
Nils Diewald7c8ced22015-04-15 19:21:00 +0000968 menu.limit(3);
969
970 expect(menu.show()).toBe(true);
971 expect(menu.prefix()).toEqual("");
972
Akron6ffad5d2016-05-24 17:16:58 +0200973 // Add prefix in uppercase - but check in lowercase
974 menu.prefix('El');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000975 expect(menu.show()).toBe(true);
976
Akron6ffad5d2016-05-24 17:16:58 +0200977 expect(menu.prefix()).toEqual("El");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000978 expect(menu._prefix.active()).toEqual(false);
979 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200980 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000981 expect(menu.shownItem(0).active()).toBe(true);
982 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200983 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000984 expect(menu.shownItem(1).active()).toBe(false);
985 expect(menu.shownItem(2)).toBe(undefined);
986
987 // Forward
988 menu.next();
Akron6ffad5d2016-05-24 17:16:58 +0200989 expect(menu.prefix()).toEqual("El");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000990 expect(menu._prefix.active()).toEqual(false);
991 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200992 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000993 expect(menu.shownItem(0).active()).toBe(false);
994 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200995 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000996 expect(menu.shownItem(1).active()).toBe(true);
997 expect(menu.shownItem(2)).toBe(undefined);
998
999 // Forward
1000 menu.next();
Akron6ffad5d2016-05-24 17:16:58 +02001001 expect(menu.prefix()).toEqual("El");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001002 expect(menu._prefix.active()).toEqual(true);
1003 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +02001004 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001005 expect(menu.shownItem(0).active()).toBe(false);
1006 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +02001007 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001008 expect(menu.shownItem(1).active()).toBe(false);
1009 expect(menu.shownItem(2)).toBe(undefined);
1010
1011 // Backward
1012 menu.prev();
Akron6ffad5d2016-05-24 17:16:58 +02001013 expect(menu.prefix()).toEqual("El");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001014 expect(menu._prefix.active()).toEqual(false);
1015 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +02001016 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001017 expect(menu.shownItem(0).active()).toBe(false);
1018
1019 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +02001020 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001021 expect(menu.shownItem(1).active()).toBe(true);
1022 expect(menu.shownItem(2)).toBe(undefined);
1023 });
1024
1025
1026 it('should be navigatable with a prefix (2)', function () {
1027 var menu = KorAP.HintMenu.create("cnx/", demolist);
Akronc1457bf2015-06-11 19:24:00 +02001028 menu._firstActive = true;
1029
Nils Diewald7c8ced22015-04-15 19:21:00 +00001030 menu.limit(3);
1031 expect(menu.show()).toBe(true);
1032 expect(menu.prefix()).toEqual("");
1033 menu.prefix('el');
1034 expect(menu.show()).toBe(true);
1035
1036 expect(menu.prefix()).toEqual("el");
1037 expect(menu._prefix.active()).toEqual(false);
1038 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +02001039 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001040 expect(menu.shownItem(0).active()).toBe(true);
1041 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +02001042 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001043 expect(menu.shownItem(1).active()).toBe(false);
1044 expect(menu.shownItem(2)).toBe(undefined);
1045
1046 // Backward
1047 menu.prev();
1048 expect(menu._prefix.active()).toEqual(true);
1049
1050 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +02001051 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001052 expect(menu.shownItem(0).active()).toBe(false);
1053
1054 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +02001055 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001056 expect(menu.shownItem(1).active()).toBe(false);
1057 expect(menu.shownItem(2)).toBe(undefined);
1058
1059 // Backward
1060 menu.prev();
1061 expect(menu._prefix.active()).toEqual(false);
1062 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +02001063 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001064 expect(menu.shownItem(0).active()).toBe(false);
1065 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +02001066 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001067 expect(menu.shownItem(1).active()).toBe(true);
1068 expect(menu.shownItem(2)).toBe(undefined);
1069 });
1070
1071 it('should be navigatable with a prefix (3)', function () {
1072 var menu = KorAP.HintMenu.create("cnx/", demolist);
Akronc1457bf2015-06-11 19:24:00 +02001073 menu._firstActive = true;
Nils Diewald7c8ced22015-04-15 19:21:00 +00001074 menu.limit(3);
1075 expect(menu.show()).toBe(true);
1076 expect(menu.prefix()).toEqual("");
1077 menu.prefix('el');
1078 expect(menu.show()).toBe(true);
1079
1080 expect(menu.prefix()).toEqual("el");
1081 expect(menu._prefix.active()).toEqual(false);
1082 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +02001083 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001084 expect(menu.shownItem(0).active()).toBe(true);
1085 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +02001086 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001087 expect(menu.shownItem(1).active()).toBe(false);
1088 expect(menu.shownItem(2)).toBe(undefined);
1089
1090 // Backward
1091 menu.prev();
1092 expect(menu._prefix.active()).toEqual(true);
1093 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +02001094 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001095 expect(menu.shownItem(0).active()).toBe(false);
1096 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +02001097 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001098 expect(menu.shownItem(1).active()).toBe(false);
1099 expect(menu.shownItem(2)).toBe(undefined);
1100
1101
1102 // Forward
1103 menu.next();
1104 expect(menu.prefix()).toEqual("el");
1105 expect(menu._prefix.active()).toEqual(false);
1106 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +02001107 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001108 expect(menu.shownItem(0).active()).toBe(true);
1109 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +02001110 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001111 expect(menu.shownItem(1).active()).toBe(false);
1112 expect(menu.shownItem(2)).toBe(undefined);
1113
1114 });
1115
Akron47c086c2016-05-18 21:22:06 +02001116 it('should show screens by offset', function () {
1117 var menu = KorAP.HintMenu.create('cnx/', demolist);
1118 menu.limit(3);
1119 expect(menu.show()).toBe(true);
1120
1121 expect(menu.shownItem(0).active()).toBe(false);
1122 expect(menu.shownItem(1).active()).toBe(false);
1123 expect(menu.shownItem(2).active()).toBe(false);
1124
Akron5240b8c2016-05-20 09:17:41 +02001125 // Highlight the first entry
Akron47c086c2016-05-18 21:22:06 +02001126 menu.next();
1127
1128 expect(menu.shownItem(0).active()).toBe(true);
1129 expect(menu.shownItem(1).active()).toBe(false);
1130 expect(menu.shownItem(2).active()).toBe(false);
1131
Akron5240b8c2016-05-20 09:17:41 +02001132 // Highlight the second entry
Akron47c086c2016-05-18 21:22:06 +02001133 menu.next();
1134
1135 expect(menu.shownItem(0).active()).toBe(false);
1136 expect(menu.shownItem(1).active()).toBe(true);
1137 expect(menu.shownItem(2).active()).toBe(false);
1138 expect(menu.shownItem(3)).toBe(undefined);
1139
1140 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1141 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1142
Akron5240b8c2016-05-20 09:17:41 +02001143 // Move to first screen
Akron47c086c2016-05-18 21:22:06 +02001144 menu.screen(0);
Akron5240b8c2016-05-20 09:17:41 +02001145 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1146 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
Akron47c086c2016-05-18 21:22:06 +02001147 expect(menu.shownItem(0).active()).toBe(false);
1148 expect(menu.shownItem(1).active()).toBe(true);
1149 expect(menu.shownItem(2).active()).toBe(false);
1150 expect(menu.shownItem(3)).toBe(undefined);
Akroncb351d62016-05-19 23:10:33 +02001151
Akron5240b8c2016-05-20 09:17:41 +02001152 // Move to second screen
Akron47c086c2016-05-18 21:22:06 +02001153 menu.screen(1);
Akron5240b8c2016-05-20 09:17:41 +02001154 expect(menu.shownItem(0).lcField()).toEqual(' untertitel');
Akron47c086c2016-05-18 21:22:06 +02001155 expect(menu.shownItem(0).active()).toBe(true);
Akron47c086c2016-05-18 21:22:06 +02001156 expect(menu.shownItem(1).active()).toBe(false);
1157 expect(menu.shownItem(2).active()).toBe(false);
Akron5240b8c2016-05-20 09:17:41 +02001158 expect(menu.shownItem(3)).toBe(undefined);
1159
1160 menu.screen(2);
1161 expect(menu.shownItem(0).lcField()).toEqual(' veröffentlichungsdatum');
1162 expect(menu.shownItem(0).active()).toBe(false);
1163 expect(menu.shownItem(1).active()).toBe(false);
1164 expect(menu.shownItem(2).active()).toBe(false);
1165 expect(menu.shownItem(3)).toBe(undefined);
1166
1167 menu.screen(1);
1168 expect(menu.shownItem(0).lcField()).toEqual(' untertitel');
1169 expect(menu.shownItem(0).active()).toBe(true);
1170 expect(menu.shownItem(1).active()).toBe(false);
1171 expect(menu.shownItem(2).active()).toBe(false);
1172 expect(menu.shownItem(3)).toBe(undefined);
Akron47c086c2016-05-18 21:22:06 +02001173 });
1174
Akron6ed13992016-05-23 18:06:05 +02001175 it('should show screens by offset when prefixed', function () {
1176 var menu = KorAP.HintMenu.create('cnx/', demolist);
1177 menu.limit(3);
1178 expect(menu.prefix("e").show()).toBe(true);
1179 expect(menu.shownItem(0).active()).toBe(false);
1180 expect(menu.shownItem(1).active()).toBe(false);
1181 expect(menu.shownItem(2).active()).toBe(false);
1182
1183 expect(menu.shownItem(0).element().innerHTML).toEqual('<strong>Tit<mark>e</mark>l</strong>');
1184 menu.screen(1);
1185 expect(menu.shownItem(0).element().innerHTML).toEqual('<strong>Unt<mark>e</mark>rtit<mark>e</mark>l</strong>');
1186 });
1187
Akron47c086c2016-05-18 21:22:06 +02001188
Akron3c2730f2016-05-24 15:08:29 +02001189 it('should be page downable', function () {
1190 var menu = KorAP.OwnMenu.create(demolonglist);
1191 menu.limit(3);
1192
1193 expect(menu.show(0)).toBe(true);
1194
1195 expect(menu.shownItem(0).active()).toBe(true);
1196 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1197 expect(menu.shownItem(1).active()).toBe(false);
1198 expect(menu.shownItem(2).active()).toBe(false);
1199 expect(menu.shownItem(3)).toBe(undefined);
1200
1201 menu.pageDown();
1202
1203 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1204 expect(menu.shownItem(0).active()).toBe(false);
1205 expect(menu.shownItem(1).active()).toBe(false);
1206 expect(menu.shownItem(2).active()).toBe(false);
1207
1208 menu.pageDown();
1209
1210 expect(menu.shownItem(0).lcField()).toEqual(' corpusid');
1211 expect(menu.shownItem(0).active()).toBe(false);
1212 expect(menu.shownItem(1).active()).toBe(false);
1213 expect(menu.shownItem(2).active()).toBe(false);
1214
1215 // Doesn't matter
1216 menu.pageDown();
1217
1218 expect(menu.shownItem(0).lcField()).toEqual(' corpusid');
1219 expect(menu.shownItem(0).active()).toBe(false);
1220 expect(menu.shownItem(1).active()).toBe(false);
1221 expect(menu.shownItem(2).active()).toBe(false);
1222 });
1223
Akron6ac58442016-05-24 16:52:29 +02001224 it('should be page downable with prefix', function () {
1225 var menu = KorAP.OwnMenu.create(demolonglist);
1226 menu.limit(3);
1227
1228 expect(menu.prefix('e').show(0)).toBe(true);
1229
1230 expect(menu.shownItem(0).active()).toBe(true);
1231 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1232 expect(menu.shownItem(1).active()).toBe(false);
1233 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1234 expect(menu.shownItem(2).active()).toBe(false);
1235 expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum');
1236 expect(menu.shownItem(3)).toBe(undefined);
1237
1238 menu.pageDown();
1239
1240 expect(menu.shownItem(0).active()).toBe(false);
1241 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1242 expect(menu.shownItem(1).active()).toBe(false);
1243 expect(menu.shownItem(1).lcField()).toEqual(' genre');
1244 expect(menu.shownItem(2).active()).toBe(false);
1245 expect(menu.shownItem(2).lcField()).toEqual(' textid');
1246
1247 // Doesn't matter
1248 menu.pageDown();
1249
1250 expect(menu.shownItem(0).active()).toBe(false);
1251 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1252 expect(menu.shownItem(1).active()).toBe(false);
1253 expect(menu.shownItem(1).lcField()).toEqual(' genre');
1254 expect(menu.shownItem(2).active()).toBe(false);
1255 expect(menu.shownItem(2).lcField()).toEqual(' textid');
1256 });
1257
1258
Akron3c2730f2016-05-24 15:08:29 +02001259 it('should be page upable', function () {
1260 var menu = KorAP.OwnMenu.create(demolonglist);
1261 menu.limit(3);
1262
1263 // Choose the final value
1264 expect(menu.show(1000)).toBe(true);
1265
1266 expect(menu.shownItem(0).active()).toBe(false);
1267 expect(menu.shownItem(1).active()).toBe(false);
1268 expect(menu.shownItem(2).active()).toBe(true);
1269 expect(menu.shownItem(2).lcField()).toEqual(' textid');
1270 expect(menu.shownItem(3)).toBe(undefined);
1271
1272 menu.pageUp();
1273
1274 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1275 expect(menu.shownItem(0).active()).toBe(false);
1276 expect(menu.shownItem(1).active()).toBe(false);
1277 expect(menu.shownItem(2).active()).toBe(false);
1278
1279 menu.pageUp();
1280
1281 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1282 expect(menu.shownItem(0).active()).toBe(false);
1283 expect(menu.shownItem(1).active()).toBe(false);
1284 expect(menu.shownItem(2).active()).toBe(false);
1285
1286 // Doesn't matter
1287 menu.pageUp();
1288
1289 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1290 expect(menu.shownItem(0).active()).toBe(false);
1291 expect(menu.shownItem(1).active()).toBe(false);
1292 expect(menu.shownItem(2).active()).toBe(false);
1293 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001294
Akron6ac58442016-05-24 16:52:29 +02001295 it('should be page upable with prefix', function () {
1296 var menu = KorAP.OwnMenu.create(demolonglist);
1297 menu.limit(3);
1298
1299 // Choose the final value
1300 expect(menu.prefix("e").show(1000)).toBe(true);
1301
1302 expect(menu.shownItem(0).active()).toBe(false);
1303 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1304 expect(menu.shownItem(1).active()).toBe(false);
1305 expect(menu.shownItem(1).lcField()).toEqual(' genre');
1306 expect(menu.shownItem(2).active()).toBe(true);
1307 expect(menu.shownItem(2).lcField()).toEqual(' textid');
1308 expect(menu.shownItem(3)).toBe(undefined);
1309
1310 menu.pageUp();
1311
1312 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1313 expect(menu.shownItem(0).active()).toBe(false);
1314 expect(menu.shownItem(1).active()).toBe(false);
1315 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1316 expect(menu.shownItem(2).active()).toBe(false);
1317 expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum');
1318
1319 // Doesn't matter
1320 menu.pageUp();
1321
1322 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1323 expect(menu.shownItem(0).active()).toBe(false);
1324 expect(menu.shownItem(1).active()).toBe(false);
1325 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1326 expect(menu.shownItem(2).active()).toBe(false);
1327 expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum');
1328 });
1329
Akron0b92f692016-05-25 22:37:13 +02001330 it('should scroll to a chosen value (1)', function () {
Akron37513a62015-11-17 01:07:11 +01001331 var menu = KorAP.OwnMenu.create(demolist);
1332 menu.limit(3);
Akron6ed13992016-05-23 18:06:05 +02001333
1334 // Choose value 1
1335 expect(menu.show(1)).toBe(true);
1336
1337 expect(menu.shownItem(0).active()).toBe(false);
1338 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1339 expect(menu.shownItem(1).active()).toBe(true);
1340 expect(menu.shownItem(2).active()).toBe(false);
1341 expect(menu.shownItem(3)).toBe(undefined);
1342
1343 // Choose value 2
1344 expect(menu.show(2)).toBe(true);
1345
1346 expect(menu.shownItem(0).active()).toBe(false);
1347 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1348 expect(menu.shownItem(1).active()).toBe(false);
1349 expect(menu.shownItem(2).active()).toBe(true);
1350 expect(menu.shownItem(3)).toBe(undefined);
Akron37513a62015-11-17 01:07:11 +01001351 });
1352
Akron0b92f692016-05-25 22:37:13 +02001353 it('should scroll to a chosen value (2)', function () {
1354 var menu = KorAP.OwnMenu.create(demolonglist);
1355
1356 // Choose value 3
1357 expect(menu.limit(3).show(3)).toBe(true);
1358 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1359 expect(menu.shownItem(0).active()).toBe(true);
1360 expect(menu.shownItem(1).active()).toBe(false);
1361 expect(menu.shownItem(2).active()).toBe(false);
1362 expect(menu.shownItem(3)).toBe(undefined);
1363 });
1364
1365 xit('should scroll to a chosen value after prefixing, if the chosen value is live');
Nils Diewald7148c6f2015-05-04 15:07:53 +00001366 });
1367
1368 describe('KorAP.Prefix', function () {
1369 it('should be initializable', function () {
1370 var p = prefixClass.create();
1371 expect(p.element().classList.contains('pref')).toBeTruthy();
1372 expect(p.isSet()).not.toBeTruthy();
1373
1374/*
1375 expect(mi.lcField()).toEqual(' baum');
1376*/
1377
1378 });
1379
1380 it('should be modifiable', function () {
1381 var p = prefixClass.create();
1382 expect(p.value()).toEqual('');
1383 expect(p.element().firstChild).toBeNull();
1384
1385 // Set string
1386 expect(p.value('Test')).toEqual('Test');
1387 expect(p.value()).toEqual('Test');
1388 expect(p.element().firstChild.nodeValue).toEqual('Test');
1389
1390 // Add string
1391 expect(p.add('ified')).toEqual('Testified');
1392 expect(p.value()).toEqual('Testified');
1393 expect(p.element().firstChild.nodeValue).toEqual('Testified');
1394
1395 // Clear string
1396 p.clear();
1397 expect(p.value()).toEqual('');
1398 expect(p.element().firstChild).toBeNull();
1399
1400 // Set string
1401 expect(p.value('Test')).toEqual('Test');
1402 expect(p.value()).toEqual('Test');
1403 expect(p.element().firstChild.nodeValue).toEqual('Test');
1404
1405 expect(p.chop()).toEqual('Tes');
1406 expect(p.value()).toEqual('Tes');
1407 expect(p.element().firstChild.nodeValue).toEqual('Tes');
1408
1409 expect(p.chop()).toEqual('Te');
1410 expect(p.value()).toEqual('Te');
1411 expect(p.element().firstChild.nodeValue).toEqual('Te');
1412
1413 expect(p.chop()).toEqual('T');
1414 expect(p.value()).toEqual('T');
1415 expect(p.element().firstChild.nodeValue).toEqual('T');
1416
1417 expect(p.chop()).toEqual('');
1418 expect(p.value()).toEqual('');
1419 expect(p.element().firstChild).toBeNull();
1420 });
1421
1422 it('should be activatable', function () {
1423 var p = prefixClass.create();
1424 expect(p.value()).toEqual('');
1425 expect(p.element().firstChild).toBeNull();
1426
1427 expect(p.value('Test')).toEqual('Test');
1428 expect(p.element().firstChild.nodeValue).toEqual('Test');
1429
1430 expect(p.active()).not.toBeTruthy();
1431 expect(p.element().classList.contains('active')).not.toBeTruthy();
1432
1433 p.active(true);
1434 expect(p.active()).toBeTruthy();
1435 expect(p.element().classList.contains('active')).toBeTruthy();
1436 });
Nils Diewaldfda29d92015-01-22 17:28:01 +00001437 });
Akronc7448732016-04-27 14:06:58 +02001438
1439 describe('KorAP.LengthField', function () {
1440 it('should be initializable', function () {
1441 var l = lengthFieldClass.create();
1442 expect(l.element().classList.contains('lengthField')).toBeTruthy();
1443 expect(l.element().children.length).toEqual(0);
1444 });
1445
1446 it('should be extensible', function () {
1447 var l = lengthFieldClass.create();
Akron1ff3ac22016-04-28 16:30:45 +02001448 l.add(['Baum']);
Akronc7448732016-04-27 14:06:58 +02001449 expect(l.element().children.length).toEqual(1);
1450 expect(l.element().children[0].nodeName).toEqual('SPAN');
Akron1ff3ac22016-04-28 16:30:45 +02001451 expect(l.element().children[0].textContent).toEqual('Baum--');
1452 l.add(['Fragezeichen']);
Akronc7448732016-04-27 14:06:58 +02001453 expect(l.element().children.length).toEqual(2);
1454 expect(l.element().children[1].nodeName).toEqual('SPAN');
Akron1ff3ac22016-04-28 16:30:45 +02001455 expect(l.element().children[1].textContent).toEqual('Fragezeichen--');
Akronc7448732016-04-27 14:06:58 +02001456 });
1457
1458 it('should be correctly initializable', function () {
1459 var list = [
1460 ["Constituency"],
1461 ["Lemma"],
1462 ["Morphology"],
1463 ["Part-of-Speech"],
1464 ["Syntax"]
1465 ];
1466
1467 var menu = KorAP.OwnMenu.create(list);
1468
1469 expect(menu.lengthField().element().children.length).toEqual(5);
1470 });
1471 });
Akronf86eaea2016-05-13 18:02:27 +02001472
1473 describe('KorAP.Slider', function () {
Akron97752a72016-05-25 14:43:07 +02001474
1475 var demolonglist = [
1476 ['Titel', 'title'],
1477 ['Untertitel', 'subTitle'],
1478 ['Veröffentlichungsdatum', 'pubDate'],
1479 ['Länge', 'length'],
1480 ['Autor', 'author'],
1481 ['Genre', 'genre'],
1482 ['corpusID', 'corpusID'],
1483 ['docID', 'docID'],
1484 ['textID', 'textID'],
1485 ];
1486
Akron6ed13992016-05-23 18:06:05 +02001487 it('should correctly be initializable', function () {
Akronf86eaea2016-05-13 18:02:27 +02001488 var list = [
1489 ["Constituency"],
1490 ["Lemma"],
1491 ["Morphology"],
1492 ["Part-of-Speech"],
1493 ["Syntax"]
1494 ];
1495
1496 var menu = KorAP.OwnMenu.create(list);
1497
1498 menu._firstActive = true;
1499 menu.limit(3);
1500
1501 expect(menu.show()).toBe(true);
1502
1503 expect(menu.shownItem(0).active()).toBe(true);
1504 expect(menu.shownItem(1).active()).toBe(false);
1505 expect(menu.shownItem(2).active()).toBe(false);
1506 expect(menu.slider().offset()).toEqual(0);
1507 expect(menu.position).toEqual(0);
Akron6ed13992016-05-23 18:06:05 +02001508 });
1509
1510 it('should correctly move on arrow keys', function () {
1511 var list = [
1512 ["Constituency"],
1513 ["Lemma"],
1514 ["Morphology"],
1515 ["Part-of-Speech"],
1516 ["Syntax"]
1517 ];
1518
1519 var menu = KorAP.OwnMenu.create(list);
1520
1521 menu._firstActive = true;
1522 menu.limit(3);
1523
1524 expect(menu.show()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +02001525
1526 menu.next();
1527 expect(menu.shownItem(0).active()).toBe(false);
1528 expect(menu.shownItem(1).active()).toBe(true);
1529 expect(menu.shownItem(2).active()).toBe(false);
1530 expect(menu.slider().offset()).toEqual(0);
1531 expect(menu.position).toEqual(1);
1532
1533 menu.next();
1534 expect(menu.shownItem(0).active()).toBe(false);
1535 expect(menu.shownItem(1).active()).toBe(false);
1536 expect(menu.shownItem(2).active()).toBe(true);
1537 expect(menu.slider().offset()).toEqual(0);
1538 expect(menu.position).toEqual(2);
1539
1540 menu.next();
1541 expect(menu.shownItem(0).active()).toBe(false);
1542 expect(menu.shownItem(1).active()).toBe(false);
1543 expect(menu.shownItem(2).active()).toBe(true);
1544 expect(menu.slider().offset()).toEqual(1);
1545 expect(menu.position).toEqual(3);
1546
1547 menu.next();
1548 expect(menu.shownItem(0).active()).toBe(false);
1549 expect(menu.shownItem(1).active()).toBe(false);
1550 expect(menu.shownItem(2).active()).toBe(true);
1551 expect(menu.slider().offset()).toEqual(2);
1552 expect(menu.position).toEqual(4);
1553
1554 menu.next();
1555 expect(menu.shownItem(0).active()).toBe(true);
1556 expect(menu.shownItem(1).active()).toBe(false);
1557 expect(menu.shownItem(2).active()).toBe(false);
1558 expect(menu.slider().offset()).toEqual(0);
1559 expect(menu.position).toEqual(0);
1560
1561 expect(menu.slider()._slider.style.height).toEqual('60%');
Akron6ed13992016-05-23 18:06:05 +02001562 });
Akronf86eaea2016-05-13 18:02:27 +02001563
Akron97752a72016-05-25 14:43:07 +02001564 it('should correctly resize on prefixing', function () {
1565 var menu = KorAP.OwnMenu.create(demolonglist);
1566 menu._firstActive = true;
1567 menu.limit(3);
1568
1569 expect(menu.show()).toBe(true);
1570 expect(menu.slider().offset()).toEqual(0);
1571 expect(menu.slider().length()).toEqual(9);
1572
1573 expect(menu.prefix("e").show()).toBe(true);
1574 expect(menu.slider().length()).toEqual(6);
1575
1576 expect(menu.prefix("el").show()).toBe(true);
1577 expect(menu.slider().length()).toEqual(2);
1578
1579 expect(menu.prefix("e").show()).toBe(true);
1580 expect(menu.slider().length()).toEqual(6);
1581
1582 expect(menu.prefix("").show()).toBe(true);
1583 expect(menu.slider().length()).toEqual(9);
1584 });
1585
1586
Akron6ed13992016-05-23 18:06:05 +02001587 it('should correctly move the list on mousemove', function () {
1588 var list = [
1589 ["Constituency"],
1590 ["Lemma"],
1591 ["Morphology"],
1592 ["Part-of-Speech"],
1593 ["Syntax"]
1594 ];
1595
1596 var menu = KorAP.OwnMenu.create(list);
1597
1598 menu._firstActive = true;
1599 menu.limit(3);
1600
1601 expect(menu.show()).toBe(true);
1602
1603 expect(menu.shownItem(0).active()).toBe(true);
1604 expect(menu.shownItem(1).active()).toBe(false);
1605 expect(menu.shownItem(2).active()).toBe(false);
1606 expect(menu.slider().offset()).toEqual(0);
1607
1608 // This will normally be done on
1609 menu.slider()._rulerHeight = 100;
1610 menu.slider()._sliderHeight = 40;
Akron71b91e42016-06-01 22:12:43 +02001611 menu.slider()._event.initOffset = 0;
Akron6ed13992016-05-23 18:06:05 +02001612 expect(menu.slider().length()).toEqual(5);
1613
1614 menu.slider().movetoRel(10);
1615 expect(menu.slider().offset()).toEqual(0);
Akron71b91e42016-06-01 22:12:43 +02001616
Akron6ed13992016-05-23 18:06:05 +02001617 expect(menu.shownItem(0).active()).toBe(true);
1618 expect(menu.shownItem(0).lcField()).toEqual(' constituency');
1619 menu.slider().movetoRel(24);
1620 expect(menu.slider().offset()).toEqual(0);
1621 menu.slider().movetoRel(25);
1622 expect(menu.slider().offset()).toEqual(0);
1623
1624 menu.slider().movetoRel(30);
1625 expect(menu.slider().offset()).toEqual(1);
1626 menu.slider().movetoRel(59);
1627 expect(menu.slider().offset()).toEqual(1);
1628 expect(menu.shownItem(0).active()).toBe(false);
1629 expect(menu.shownItem(0).lcField()).toEqual(' lemma');
1630
1631 // Everything > 60 is offset 2
1632 menu.slider().movetoRel(60);
1633 expect(menu.slider().offset()).toEqual(2);
1634 menu.slider().movetoRel(180);
1635 expect(menu.slider().offset()).toEqual(2);
1636 expect(menu.shownItem(0).active()).toBe(false);
1637 expect(menu.shownItem(0).lcField()).toEqual(' morphology');
Akron5a1f5bb2016-05-23 22:00:39 +02001638
1639 expect(menu.shownItem(1).active()).toBe(false);
1640 expect(menu.shownItem(2).active()).toBe(false);
1641
1642 // When the active cursor moves again - scroll to viewport
1643 // cursor is before viewport
1644 menu.next();
1645 expect(menu.shownItem(0).active()).toBe(true);
1646 expect(menu.shownItem(0).lcField()).toEqual(' lemma');
1647 expect(menu.shownItem(1).active()).toBe(false);
1648 expect(menu.shownItem(2).active()).toBe(false);
1649
1650 menu.next();
1651 menu.next();
1652 expect(menu.shownItem(0).active()).toBe(false);
1653 expect(menu.shownItem(0).lcField()).toEqual(' lemma');
1654 expect(menu.shownItem(1).active()).toBe(false);
1655 expect(menu.shownItem(1).lcField()).toEqual(' morphology');
1656 expect(menu.shownItem(2).active()).toBe(true);
1657 expect(menu.shownItem(2).lcField()).toEqual(' part-of-speech');
1658
1659 menu.slider().movetoRel(0);
1660 expect(menu.slider().offset()).toEqual(0);
1661 expect(menu.shownItem(0).active()).toBe(false);
1662 expect(menu.shownItem(0).lcField()).toEqual(' constituency');
1663 expect(menu.shownItem(1).active()).toBe(false);
1664 expect(menu.shownItem(1).lcField()).toEqual(' lemma');
1665 expect(menu.shownItem(2).active()).toBe(false);
1666 expect(menu.shownItem(2).lcField()).toEqual(' morphology');
1667
1668 // cursor is after viewport
1669 menu.next();
1670 expect(menu.slider().offset()).toEqual(2);
1671 expect(menu.shownItem(0).active()).toBe(false);
1672 expect(menu.shownItem(0).lcField()).toEqual(' morphology');
1673 expect(menu.shownItem(1).active()).toBe(false);
1674 expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech');
1675 expect(menu.shownItem(2).active()).toBe(true);
1676 expect(menu.shownItem(2).lcField()).toEqual(' syntax');
1677
1678 menu.slider().movetoRel(0);
1679 expect(menu.slider().offset()).toEqual(0);
1680 expect(menu.shownItem(0).active()).toBe(false);
1681 expect(menu.shownItem(0).lcField()).toEqual(' constituency');
1682 expect(menu.shownItem(1).active()).toBe(false);
1683 expect(menu.shownItem(1).lcField()).toEqual(' lemma');
1684 expect(menu.shownItem(2).active()).toBe(false);
1685 expect(menu.shownItem(2).lcField()).toEqual(' morphology');
1686
1687 menu.prev();
1688 expect(menu.slider().offset()).toEqual(2);
1689 expect(menu.shownItem(0).lcField()).toEqual(' morphology');
1690 expect(menu.shownItem(0).active()).toBe(false);
1691 expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech');
1692 expect(menu.shownItem(1).active()).toBe(true);
1693 expect(menu.shownItem(2).lcField()).toEqual(' syntax');
1694 expect(menu.shownItem(2).active()).toBe(false);
1695
1696 menu.prev();
1697 menu.prev();
1698 expect(menu.slider().offset()).toEqual(1);
1699 expect(menu.shownItem(0).lcField()).toEqual(' lemma');
1700 expect(menu.shownItem(0).active()).toBe(true);
1701 expect(menu.shownItem(1).lcField()).toEqual(' morphology');
1702 expect(menu.shownItem(1).active()).toBe(false);
1703 expect(menu.shownItem(2).lcField()).toEqual(' part-of-speech');
1704 expect(menu.shownItem(2).active()).toBe(false);
1705
1706 menu.slider().movetoRel(100);
1707 expect(menu.slider().offset()).toEqual(2);
1708 expect(menu.shownItem(0).lcField()).toEqual(' morphology');
1709 expect(menu.shownItem(0).active()).toBe(false);
1710 expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech');
1711 expect(menu.shownItem(1).active()).toBe(false);
1712 expect(menu.shownItem(2).lcField()).toEqual(' syntax');
1713 expect(menu.shownItem(2).active()).toBe(false);
1714
1715 menu.prev();
1716 expect(menu.slider().offset()).toEqual(0);
1717 expect(menu.shownItem(0).lcField()).toEqual(' constituency');
1718 expect(menu.shownItem(0).active()).toBe(true);
1719 expect(menu.shownItem(1).lcField()).toEqual(' lemma');
1720 expect(menu.shownItem(1).active()).toBe(false);
1721 expect(menu.shownItem(2).lcField()).toEqual(' morphology');
1722 expect(menu.shownItem(2).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +02001723 });
1724 });
Akron7524be12016-06-01 17:31:33 +02001725
1726 describe('KorAP.MenuBenchmark', function () {
1727 var menu = menuClass.create([
1728 ['Titel', 'title'],
1729 ['Untertitel', 'subTitle'],
1730 ['Veröffentlichungsdatum', 'pubDate'],
1731 ['Länge', 'length'],
1732 ['Autor', 'author']
1733 ]);
1734
1735 menu.limit(3).show();
1736
1737 // Some actions
1738 menu.next();
1739 menu.next();
1740 menu.prev();
1741 menu.prev();
1742 menu.prev();
1743
1744 menu.pageDown();
1745 menu.pageUp();
1746
1747 // There is no fourth item in the list!
1748 menu.prefix('e').show(4);
1749 menu.next();
1750 menu.next();
1751 menu.prev();
1752 menu.prev();
1753 menu.prev();
1754 });
Nils Diewaldfda29d92015-01-22 17:28:01 +00001755});