blob: 55ee44be6f01da26f51fbc64b600ac4ac69eace1 [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 = {
28 create : function (params) {
29 return Object.create(menuClass)
30 .upgradeTo(KorAP.OwnMenu)
Akron1ff3ac22016-04-28 16:30:45 +020031 ._init(KorAP.OwnMenuItem, undefined, undefined, params);
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 = {
102 create : function (context, params) {
103 var obj = Object.create(menuClass)
104 .upgradeTo(KorAP.HintMenu)
Akron1ff3ac22016-04-28 16:30:45 +0200105 ._init(KorAP.HintMenuItem, undefined, undefined, params);
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');
363 expect(menu.element().style.opacity).toEqual("0");
364 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
538 it('should be prevable', function () {
539 var menu = KorAP.HintMenu.create("cnx/", list);
Akronc1457bf2015-06-11 19:24:00 +0200540 menu._firstActive = true;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000541 menu.limit(3);
542 expect(menu.show()).toBe(true);
543
Akronf86eaea2016-05-13 18:02:27 +0200544 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000545 expect(menu.shownItem(0).active()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +0200546 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000547 expect(menu.shownItem(1).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200548 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000549 expect(menu.shownItem(2).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200550 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000551
552 // Activate prev (1) - roll to bottom
553 menu.prev();
Akronf86eaea2016-05-13 18:02:27 +0200554 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000555 expect(menu.shownItem(0).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200556 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000557 expect(menu.shownItem(1).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200558 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Syntax</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000559 expect(menu.shownItem(2).active()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +0200560 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000561
562 // Activate prev (2)
563 menu.prev();
Akronf86eaea2016-05-13 18:02:27 +0200564 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000565 expect(menu.shownItem(0).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200566 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000567 expect(menu.shownItem(1).active()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +0200568 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Syntax</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000569 expect(menu.shownItem(2).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200570 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000571
572 // Activate prev (3)
573 menu.prev();
574 expect(menu.shownItem(0).name()).toEqual("Morphology");
575 expect(menu.shownItem(0).active()).toBe(true);
576 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
577 expect(menu.shownItem(1).active()).toBe(false);
578 expect(menu.shownItem(2).name()).toEqual("Syntax");
579 expect(menu.shownItem(2).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200580 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000581
582 // Activate prev (4)
583 menu.prev();
584 expect(menu.shownItem(0).name()).toEqual("Lemma");
585 expect(menu.shownItem(0).active()).toBe(true);
586 expect(menu.shownItem(1).name()).toEqual("Morphology");
587 expect(menu.shownItem(1).active()).toBe(false);
588 expect(menu.shownItem(2).name()).toEqual("Part-of-Speech");
589 expect(menu.shownItem(2).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200590 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000591
592 // Activate prev (5)
593 menu.prev();
594 expect(menu.shownItem(0).name()).toEqual("Constituency");
595 expect(menu.shownItem(0).active()).toBe(true);
596 expect(menu.shownItem(1).name()).toEqual("Lemma");
597 expect(menu.shownItem(1).active()).toBe(false);
598 expect(menu.shownItem(2).name()).toEqual("Morphology");
599 expect(menu.shownItem(2).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200600 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000601
602 // Activate next (1)
603 menu.next();
604 expect(menu.shownItem(0).name()).toEqual("Constituency");
605 expect(menu.shownItem(0).active()).toBe(false);
606 expect(menu.shownItem(1).name()).toEqual("Lemma");
607 expect(menu.shownItem(1).active()).toBe(true);
608 expect(menu.shownItem(2).name()).toEqual("Morphology");
609 expect(menu.shownItem(2).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200610 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000611
612 // Activate prev (6)
613 menu.prev();
614
615 // Activate prev (7)
616 menu.prev();
617 expect(menu.shownItem(0).name()).toEqual("Morphology");
618 expect(menu.shownItem(0).active()).toBe(false);
619 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
620 expect(menu.shownItem(1).active()).toBe(false);
621 expect(menu.shownItem(2).name()).toEqual("Syntax");
622 expect(menu.shownItem(2).active()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +0200623 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000624 });
625
626
627 it('should be navigatable and filterable (prefix = "o")', function () {
628 var menu = KorAP.HintMenu.create("cnx/", list);
Akronc1457bf2015-06-11 19:24:00 +0200629 menu._firstActive = true;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000630 menu.limit(2);
631
632 expect(menu.prefix("o").show()).toBe(true);
633 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200634 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 +0000635 expect(menu.shownItem(0).active()).toBe(true);
636 expect(menu.shownItem(1).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200637 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 +0000638 expect(menu.shownItem(1).active()).toBe(false);
639 expect(menu.shownItem(2)).toBe(undefined);
640
641 // Next (1)
642 menu.next();
643 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200644 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 +0000645 expect(menu.shownItem(0).active()).toBe(false);
646 expect(menu.shownItem(1).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200647 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 +0000648 expect(menu.shownItem(1).active()).toBe(true);
649 expect(menu.shownItem(2)).toBe(undefined);
650
651 // Next (2)
652 menu.next();
653 expect(menu.shownItem(0).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200654 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 +0000655 expect(menu.shownItem(0).active()).toBe(false);
656 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
Akronf86eaea2016-05-13 18:02:27 +0200657 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000658 expect(menu.shownItem(1).active()).toBe(true);
659 expect(menu.shownItem(2)).toBe(undefined);
660
661 // Next (3) - to prefix
662 menu.next();
663 expect(menu.shownItem(0).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200664 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 +0000665 expect(menu.shownItem(0).active()).toBe(false);
666 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
Akronf86eaea2016-05-13 18:02:27 +0200667 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000668 expect(menu.shownItem(1).active()).toBe(false);
669 expect(menu.shownItem(2)).toBe(undefined);
670
671 menu.next();
672 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200673 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 +0000674 expect(menu.shownItem(0).active()).toBe(true);
675 expect(menu.shownItem(1).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200676 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 +0000677 expect(menu.shownItem(1).active()).toBe(false);
678 expect(menu.shownItem(2)).toBe(undefined);
679 });
680
681
682 it('should be navigatable and filterable (prefix = "ex", "e")', function () {
683 var menu = KorAP.HintMenu.create("cnx/", list);
Akronc1457bf2015-06-11 19:24:00 +0200684 menu._firstActive = true;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000685
686 menu.limit(2);
687 expect(menu.prefix("ex").show()).toBe(true);
688
689 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200690 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 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>Morphology</strong><span><mark>Ex</mark>ample 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 // Next (1)
698 menu.next();
699 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200700 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000701 expect(menu.shownItem(0).active()).toBe(false);
702 expect(menu.shownItem(1).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200703 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000704 expect(menu.shownItem(1).active()).toBe(true);
705 expect(menu.shownItem(2)).toBe(undefined);
706
707 // Next (2)
708 menu.next();
709
710 expect(menu.prefix()).toEqual('ex');
711 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200712 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000713 expect(menu.shownItem(0).active()).toBe(false);
714
715 expect(menu.shownItem(1).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200716 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000717 expect(menu.shownItem(1).active()).toBe(false);
718 expect(menu.shownItem(2)).toBe(undefined);
719
720 // Reset limit
721 menu.limit(5);
722
723 // Change show
724 expect(menu.prefix("e").show()).toBe(true);
725 expect(menu._prefix.active()).toBe(false);
726 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200727 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 +0000728 expect(menu.shownItem(0).active()).toBe(true);
729 expect(menu.shownItem(1).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200730 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 +0000731 expect(menu.shownItem(1).active()).toBe(false);
732 expect(menu.shownItem(2)).toBe(undefined);
733
734 // Next (1)
735 menu.next();
736 expect(menu._prefix.active()).toBe(false);
737 expect(menu.prefix()).toEqual('e');
738 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200739 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 +0000740 expect(menu.shownItem(0).active()).toBe(false);
741 expect(menu.shownItem(1).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200742 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 +0000743 expect(menu.shownItem(1).active()).toBe(true);
744 expect(menu.shownItem(2)).toBe(undefined);
745
746 // Next (2)
747 menu.next();
748 expect(menu._prefix.active()).toBe(true);
749 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200750 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 +0000751 expect(menu.shownItem(0).active()).toBe(false);
752 expect(menu.shownItem(1).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200753 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 +0000754 expect(menu.shownItem(1).active()).toBe(false);
755 expect(menu.shownItem(2)).toBe(undefined);
756
757 // Next (3)
758 menu.next();
759 expect(menu._prefix.active()).toBe(false);
760 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200761 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 +0000762 expect(menu.shownItem(0).active()).toBe(true);
763 expect(menu.shownItem(1).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200764 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 +0000765 expect(menu.shownItem(1).active()).toBe(false);
766 expect(menu.shownItem(2)).toBe(undefined);
767 });
768
769
Akrona92fd8d2016-05-24 21:13:41 +0200770 it('should choose prefix with failing prefix (1)', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000771 var menu = KorAP.HintMenu.create("cnx/", list);
772 menu.limit(2);
Akron6ed13992016-05-23 18:06:05 +0200773 expect(menu.prefix("exit").show()).toBe(true);
Akrona92fd8d2016-05-24 21:13:41 +0200774 expect(menu.element().querySelector('li')).toBe(null);
775 expect(menu.shownItem(0)).toBeUndefined();
776 expect(menu._prefix.active()).toBe(true);
777 });
778
779
780 it('should choose prefix with failing prefix (2)', function () {
781 var menu = KorAP.HintMenu.create("cnx/", list);
782 menu.limit(2);
783 expect(menu.show()).toBe(true);
784 expect(menu.prefix("exit").show()).toBe(true);
785 expect(menu.element().querySelector('li')).toBe(null);
Akron6ed13992016-05-23 18:06:05 +0200786 expect(menu.shownItem(0)).toBeUndefined();
787 expect(menu._prefix.active()).toBe(true);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000788 });
789
Akronb38afb22016-05-25 19:30:01 +0200790 it('should ignore navigation with failing prefix', function () {
791 var menu = KorAP.HintMenu.create("cnx/", list);
792 menu.limit(2);
793 expect(menu.show()).toBe(true);
794
795 menu.next();
796
797 expect(menu.prefix("exit").show()).toBe(true);
798 expect(menu.element().querySelector('li')).toBe(null);
799 expect(menu.shownItem(0)).toBeUndefined();
800 expect(menu._prefix.active()).toBe(true);
801
802 menu.next();
803 expect(menu._prefix.active()).toBe(true);
804
805 menu.prev();
806 expect(menu._prefix.active()).toBe(true);
807
808 });
Akron37513a62015-11-17 01:07:11 +0100809
Nils Diewald7c8ced22015-04-15 19:21:00 +0000810 it('should be navigatable with prefix', function () {
811 var menu = KorAP.HintMenu.create("cnx/", demolist);
Akronc1457bf2015-06-11 19:24:00 +0200812 menu._firstActive = true;
813
Nils Diewald7c8ced22015-04-15 19:21:00 +0000814 menu.limit(3);
815
816 expect(menu.show()).toBe(true);
817 expect(menu.prefix()).toEqual("");
818
819 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200820 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000821 expect(menu.shownItem(0).active()).toBe(true);
822 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200823 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000824 expect(menu.shownItem(1).active()).toBe(false);
825 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200826 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000827 expect(menu.shownItem(2).active()).toBe(false);
828 expect(menu.shownItem(3)).toBe(undefined);
829
830 menu._prefix.add('a');
831 expect(menu.show()).toBe(true);
832 expect(menu.prefix()).toEqual("a");
833 expect(menu.shownItem(0).name()).toEqual("Autor");
Akronf86eaea2016-05-13 18:02:27 +0200834 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000835
836 menu._prefix.add('u');
837 expect(menu.show()).toBe(true);
838 expect(menu.prefix()).toEqual("au");
839 expect(menu.shownItem(0).name()).toEqual("Autor");
Akronf86eaea2016-05-13 18:02:27 +0200840 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong><mark>Au</mark>tor</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000841
Nils Diewald7148c6f2015-05-04 15:07:53 +0000842 menu._prefix.chop();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000843 expect(menu.show()).toBe(true);
844 expect(menu.prefix()).toEqual("a");
845 expect(menu.shownItem(0).name()).toEqual("Autor");
Akronf86eaea2016-05-13 18:02:27 +0200846 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000847
Nils Diewald7148c6f2015-05-04 15:07:53 +0000848 menu._prefix.chop();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000849 expect(menu.show()).toBe(true);
850 expect(menu.prefix()).toEqual("");
851 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200852 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000853 expect(menu.shownItem(0).active()).toBe(true);
854 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200855 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000856 expect(menu.shownItem(1).active()).toBe(false);
857 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200858 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000859 expect(menu.shownItem(2).active()).toBe(false);
860 expect(menu.shownItem(3)).toBe(undefined);
861
862 // Forward
Nils Diewald7148c6f2015-05-04 15:07:53 +0000863 menu._prefix.chop();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000864 expect(menu.show()).toBe(true);
865 expect(menu.prefix()).toEqual("");
866 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200867 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000868 expect(menu.shownItem(0).active()).toBe(true);
869 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200870 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000871 expect(menu.shownItem(1).active()).toBe(false);
872 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200873 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000874 expect(menu.shownItem(2).active()).toBe(false);
875
876 // Forward
877 menu.next();
878 expect(menu.prefix()).toEqual("");
879 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200880 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000881 expect(menu.shownItem(0).active()).toBe(false);
882 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200883 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000884 expect(menu.shownItem(1).active()).toBe(true);
885 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200886 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000887 expect(menu.shownItem(2).active()).toBe(false);
888 expect(menu.shownItem(3)).toBe(undefined);
889
890 // Forward
891 menu.next();
892 expect(menu.prefix()).toEqual("");
893 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200894 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000895 expect(menu.shownItem(0).active()).toBe(false);
896 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200897 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000898 expect(menu.shownItem(1).active()).toBe(false);
899 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200900 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000901 expect(menu.shownItem(2).active()).toBe(true);
902 expect(menu.shownItem(3)).toBe(undefined);
903
904 // Forward
905 menu.next();
906 expect(menu.prefix()).toEqual("");
907 expect(menu.shownItem(0).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200908 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Untertitel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000909 expect(menu.shownItem(0).active()).toBe(false);
910 expect(menu.shownItem(1).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200911 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000912 expect(menu.shownItem(1).active()).toBe(false);
913 expect(menu.shownItem(2).name()).toEqual("Länge");
Akronf86eaea2016-05-13 18:02:27 +0200914 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Länge</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000915 expect(menu.shownItem(2).active()).toBe(true);
916 expect(menu.shownItem(3)).toBe(undefined);
917
918 // Forward
919 menu.next();
920 expect(menu.prefix()).toEqual("");
921 expect(menu.shownItem(0).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200922 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000923 expect(menu.shownItem(0).active()).toBe(false);
924 expect(menu.shownItem(1).name()).toEqual("Länge");
Akronf86eaea2016-05-13 18:02:27 +0200925 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Länge</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000926 expect(menu.shownItem(1).active()).toBe(false);
927 expect(menu.shownItem(2).name()).toEqual("Autor");
Akronf86eaea2016-05-13 18:02:27 +0200928 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Autor</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000929 expect(menu.shownItem(2).active()).toBe(true);
930 expect(menu.shownItem(3)).toBe(undefined);
931
932 // Forward
933 menu.next();
934 expect(menu.prefix()).toEqual("");
935 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200936 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000937 expect(menu.shownItem(0).active()).toBe(true);
938 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200939 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000940 expect(menu.shownItem(1).active()).toBe(false);
941 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200942 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000943 expect(menu.shownItem(2).active()).toBe(false);
944 });
945
946
947 it('should be navigatable with a prefix (1)', function () {
948 var menu = KorAP.HintMenu.create("cnx/", demolist);
Akronc1457bf2015-06-11 19:24:00 +0200949 menu._firstActive = true;
950
Nils Diewald7c8ced22015-04-15 19:21:00 +0000951 menu.limit(3);
952
953 expect(menu.show()).toBe(true);
954 expect(menu.prefix()).toEqual("");
955
Akron6ffad5d2016-05-24 17:16:58 +0200956 // Add prefix in uppercase - but check in lowercase
957 menu.prefix('El');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000958 expect(menu.show()).toBe(true);
959
Akron6ffad5d2016-05-24 17:16:58 +0200960 expect(menu.prefix()).toEqual("El");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000961 expect(menu._prefix.active()).toEqual(false);
962 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200963 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000964 expect(menu.shownItem(0).active()).toBe(true);
965 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200966 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000967 expect(menu.shownItem(1).active()).toBe(false);
968 expect(menu.shownItem(2)).toBe(undefined);
969
970 // Forward
971 menu.next();
Akron6ffad5d2016-05-24 17:16:58 +0200972 expect(menu.prefix()).toEqual("El");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000973 expect(menu._prefix.active()).toEqual(false);
974 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200975 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000976 expect(menu.shownItem(0).active()).toBe(false);
977 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200978 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000979 expect(menu.shownItem(1).active()).toBe(true);
980 expect(menu.shownItem(2)).toBe(undefined);
981
982 // Forward
983 menu.next();
Akron6ffad5d2016-05-24 17:16:58 +0200984 expect(menu.prefix()).toEqual("El");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000985 expect(menu._prefix.active()).toEqual(true);
986 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200987 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000988 expect(menu.shownItem(0).active()).toBe(false);
989 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200990 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000991 expect(menu.shownItem(1).active()).toBe(false);
992 expect(menu.shownItem(2)).toBe(undefined);
993
994 // Backward
995 menu.prev();
Akron6ffad5d2016-05-24 17:16:58 +0200996 expect(menu.prefix()).toEqual("El");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000997 expect(menu._prefix.active()).toEqual(false);
998 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200999 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001000 expect(menu.shownItem(0).active()).toBe(false);
1001
1002 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +02001003 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001004 expect(menu.shownItem(1).active()).toBe(true);
1005 expect(menu.shownItem(2)).toBe(undefined);
1006 });
1007
1008
1009 it('should be navigatable with a prefix (2)', function () {
1010 var menu = KorAP.HintMenu.create("cnx/", demolist);
Akronc1457bf2015-06-11 19:24:00 +02001011 menu._firstActive = true;
1012
Nils Diewald7c8ced22015-04-15 19:21:00 +00001013 menu.limit(3);
1014 expect(menu.show()).toBe(true);
1015 expect(menu.prefix()).toEqual("");
1016 menu.prefix('el');
1017 expect(menu.show()).toBe(true);
1018
1019 expect(menu.prefix()).toEqual("el");
1020 expect(menu._prefix.active()).toEqual(false);
1021 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +02001022 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001023 expect(menu.shownItem(0).active()).toBe(true);
1024 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +02001025 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001026 expect(menu.shownItem(1).active()).toBe(false);
1027 expect(menu.shownItem(2)).toBe(undefined);
1028
1029 // Backward
1030 menu.prev();
1031 expect(menu._prefix.active()).toEqual(true);
1032
1033 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +02001034 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001035 expect(menu.shownItem(0).active()).toBe(false);
1036
1037 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +02001038 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001039 expect(menu.shownItem(1).active()).toBe(false);
1040 expect(menu.shownItem(2)).toBe(undefined);
1041
1042 // Backward
1043 menu.prev();
1044 expect(menu._prefix.active()).toEqual(false);
1045 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +02001046 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001047 expect(menu.shownItem(0).active()).toBe(false);
1048 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +02001049 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001050 expect(menu.shownItem(1).active()).toBe(true);
1051 expect(menu.shownItem(2)).toBe(undefined);
1052 });
1053
1054 it('should be navigatable with a prefix (3)', function () {
1055 var menu = KorAP.HintMenu.create("cnx/", demolist);
Akronc1457bf2015-06-11 19:24:00 +02001056 menu._firstActive = true;
Nils Diewald7c8ced22015-04-15 19:21:00 +00001057 menu.limit(3);
1058 expect(menu.show()).toBe(true);
1059 expect(menu.prefix()).toEqual("");
1060 menu.prefix('el');
1061 expect(menu.show()).toBe(true);
1062
1063 expect(menu.prefix()).toEqual("el");
1064 expect(menu._prefix.active()).toEqual(false);
1065 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +02001066 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001067 expect(menu.shownItem(0).active()).toBe(true);
1068 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +02001069 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001070 expect(menu.shownItem(1).active()).toBe(false);
1071 expect(menu.shownItem(2)).toBe(undefined);
1072
1073 // Backward
1074 menu.prev();
1075 expect(menu._prefix.active()).toEqual(true);
1076 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +02001077 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001078 expect(menu.shownItem(0).active()).toBe(false);
1079 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +02001080 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001081 expect(menu.shownItem(1).active()).toBe(false);
1082 expect(menu.shownItem(2)).toBe(undefined);
1083
1084
1085 // Forward
1086 menu.next();
1087 expect(menu.prefix()).toEqual("el");
1088 expect(menu._prefix.active()).toEqual(false);
1089 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +02001090 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001091 expect(menu.shownItem(0).active()).toBe(true);
1092 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +02001093 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001094 expect(menu.shownItem(1).active()).toBe(false);
1095 expect(menu.shownItem(2)).toBe(undefined);
1096
1097 });
1098
Akron47c086c2016-05-18 21:22:06 +02001099 it('should show screens by offset', function () {
1100 var menu = KorAP.HintMenu.create('cnx/', demolist);
1101 menu.limit(3);
1102 expect(menu.show()).toBe(true);
1103
1104 expect(menu.shownItem(0).active()).toBe(false);
1105 expect(menu.shownItem(1).active()).toBe(false);
1106 expect(menu.shownItem(2).active()).toBe(false);
1107
Akron5240b8c2016-05-20 09:17:41 +02001108 // Highlight the first entry
Akron47c086c2016-05-18 21:22:06 +02001109 menu.next();
1110
1111 expect(menu.shownItem(0).active()).toBe(true);
1112 expect(menu.shownItem(1).active()).toBe(false);
1113 expect(menu.shownItem(2).active()).toBe(false);
1114
Akron5240b8c2016-05-20 09:17:41 +02001115 // Highlight the second entry
Akron47c086c2016-05-18 21:22:06 +02001116 menu.next();
1117
1118 expect(menu.shownItem(0).active()).toBe(false);
1119 expect(menu.shownItem(1).active()).toBe(true);
1120 expect(menu.shownItem(2).active()).toBe(false);
1121 expect(menu.shownItem(3)).toBe(undefined);
1122
1123 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1124 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1125
Akron5240b8c2016-05-20 09:17:41 +02001126 // Move to first screen
Akron47c086c2016-05-18 21:22:06 +02001127 menu.screen(0);
Akron5240b8c2016-05-20 09:17:41 +02001128 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1129 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
Akron47c086c2016-05-18 21:22:06 +02001130 expect(menu.shownItem(0).active()).toBe(false);
1131 expect(menu.shownItem(1).active()).toBe(true);
1132 expect(menu.shownItem(2).active()).toBe(false);
1133 expect(menu.shownItem(3)).toBe(undefined);
Akroncb351d62016-05-19 23:10:33 +02001134
Akron5240b8c2016-05-20 09:17:41 +02001135 // Move to second screen
Akron47c086c2016-05-18 21:22:06 +02001136 menu.screen(1);
Akron5240b8c2016-05-20 09:17:41 +02001137 expect(menu.shownItem(0).lcField()).toEqual(' untertitel');
Akron47c086c2016-05-18 21:22:06 +02001138 expect(menu.shownItem(0).active()).toBe(true);
Akron47c086c2016-05-18 21:22:06 +02001139 expect(menu.shownItem(1).active()).toBe(false);
1140 expect(menu.shownItem(2).active()).toBe(false);
Akron5240b8c2016-05-20 09:17:41 +02001141 expect(menu.shownItem(3)).toBe(undefined);
1142
1143 menu.screen(2);
1144 expect(menu.shownItem(0).lcField()).toEqual(' veröffentlichungsdatum');
1145 expect(menu.shownItem(0).active()).toBe(false);
1146 expect(menu.shownItem(1).active()).toBe(false);
1147 expect(menu.shownItem(2).active()).toBe(false);
1148 expect(menu.shownItem(3)).toBe(undefined);
1149
1150 menu.screen(1);
1151 expect(menu.shownItem(0).lcField()).toEqual(' untertitel');
1152 expect(menu.shownItem(0).active()).toBe(true);
1153 expect(menu.shownItem(1).active()).toBe(false);
1154 expect(menu.shownItem(2).active()).toBe(false);
1155 expect(menu.shownItem(3)).toBe(undefined);
Akron47c086c2016-05-18 21:22:06 +02001156 });
1157
Akron6ed13992016-05-23 18:06:05 +02001158 it('should show screens by offset when prefixed', function () {
1159 var menu = KorAP.HintMenu.create('cnx/', demolist);
1160 menu.limit(3);
1161 expect(menu.prefix("e").show()).toBe(true);
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
1166 expect(menu.shownItem(0).element().innerHTML).toEqual('<strong>Tit<mark>e</mark>l</strong>');
1167 menu.screen(1);
1168 expect(menu.shownItem(0).element().innerHTML).toEqual('<strong>Unt<mark>e</mark>rtit<mark>e</mark>l</strong>');
1169 });
1170
Akron47c086c2016-05-18 21:22:06 +02001171
Akron3c2730f2016-05-24 15:08:29 +02001172 it('should be page downable', function () {
1173 var menu = KorAP.OwnMenu.create(demolonglist);
1174 menu.limit(3);
1175
1176 expect(menu.show(0)).toBe(true);
1177
1178 expect(menu.shownItem(0).active()).toBe(true);
1179 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1180 expect(menu.shownItem(1).active()).toBe(false);
1181 expect(menu.shownItem(2).active()).toBe(false);
1182 expect(menu.shownItem(3)).toBe(undefined);
1183
1184 menu.pageDown();
1185
1186 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1187 expect(menu.shownItem(0).active()).toBe(false);
1188 expect(menu.shownItem(1).active()).toBe(false);
1189 expect(menu.shownItem(2).active()).toBe(false);
1190
1191 menu.pageDown();
1192
1193 expect(menu.shownItem(0).lcField()).toEqual(' corpusid');
1194 expect(menu.shownItem(0).active()).toBe(false);
1195 expect(menu.shownItem(1).active()).toBe(false);
1196 expect(menu.shownItem(2).active()).toBe(false);
1197
1198 // Doesn't matter
1199 menu.pageDown();
1200
1201 expect(menu.shownItem(0).lcField()).toEqual(' corpusid');
1202 expect(menu.shownItem(0).active()).toBe(false);
1203 expect(menu.shownItem(1).active()).toBe(false);
1204 expect(menu.shownItem(2).active()).toBe(false);
1205 });
1206
Akron6ac58442016-05-24 16:52:29 +02001207 it('should be page downable with prefix', function () {
1208 var menu = KorAP.OwnMenu.create(demolonglist);
1209 menu.limit(3);
1210
1211 expect(menu.prefix('e').show(0)).toBe(true);
1212
1213 expect(menu.shownItem(0).active()).toBe(true);
1214 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1215 expect(menu.shownItem(1).active()).toBe(false);
1216 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1217 expect(menu.shownItem(2).active()).toBe(false);
1218 expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum');
1219 expect(menu.shownItem(3)).toBe(undefined);
1220
1221 menu.pageDown();
1222
1223 expect(menu.shownItem(0).active()).toBe(false);
1224 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1225 expect(menu.shownItem(1).active()).toBe(false);
1226 expect(menu.shownItem(1).lcField()).toEqual(' genre');
1227 expect(menu.shownItem(2).active()).toBe(false);
1228 expect(menu.shownItem(2).lcField()).toEqual(' textid');
1229
1230 // Doesn't matter
1231 menu.pageDown();
1232
1233 expect(menu.shownItem(0).active()).toBe(false);
1234 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1235 expect(menu.shownItem(1).active()).toBe(false);
1236 expect(menu.shownItem(1).lcField()).toEqual(' genre');
1237 expect(menu.shownItem(2).active()).toBe(false);
1238 expect(menu.shownItem(2).lcField()).toEqual(' textid');
1239 });
1240
1241
Akron3c2730f2016-05-24 15:08:29 +02001242 it('should be page upable', function () {
1243 var menu = KorAP.OwnMenu.create(demolonglist);
1244 menu.limit(3);
1245
1246 // Choose the final value
1247 expect(menu.show(1000)).toBe(true);
1248
1249 expect(menu.shownItem(0).active()).toBe(false);
1250 expect(menu.shownItem(1).active()).toBe(false);
1251 expect(menu.shownItem(2).active()).toBe(true);
1252 expect(menu.shownItem(2).lcField()).toEqual(' textid');
1253 expect(menu.shownItem(3)).toBe(undefined);
1254
1255 menu.pageUp();
1256
1257 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1258 expect(menu.shownItem(0).active()).toBe(false);
1259 expect(menu.shownItem(1).active()).toBe(false);
1260 expect(menu.shownItem(2).active()).toBe(false);
1261
1262 menu.pageUp();
1263
1264 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1265 expect(menu.shownItem(0).active()).toBe(false);
1266 expect(menu.shownItem(1).active()).toBe(false);
1267 expect(menu.shownItem(2).active()).toBe(false);
1268
1269 // Doesn't matter
1270 menu.pageUp();
1271
1272 expect(menu.shownItem(0).lcField()).toEqual(' titel');
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 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001277
Akron6ac58442016-05-24 16:52:29 +02001278 it('should be page upable with prefix', function () {
1279 var menu = KorAP.OwnMenu.create(demolonglist);
1280 menu.limit(3);
1281
1282 // Choose the final value
1283 expect(menu.prefix("e").show(1000)).toBe(true);
1284
1285 expect(menu.shownItem(0).active()).toBe(false);
1286 expect(menu.shownItem(0).lcField()).toEqual(' länge');
1287 expect(menu.shownItem(1).active()).toBe(false);
1288 expect(menu.shownItem(1).lcField()).toEqual(' genre');
1289 expect(menu.shownItem(2).active()).toBe(true);
1290 expect(menu.shownItem(2).lcField()).toEqual(' textid');
1291 expect(menu.shownItem(3)).toBe(undefined);
1292
1293 menu.pageUp();
1294
1295 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1296 expect(menu.shownItem(0).active()).toBe(false);
1297 expect(menu.shownItem(1).active()).toBe(false);
1298 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1299 expect(menu.shownItem(2).active()).toBe(false);
1300 expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum');
1301
1302 // Doesn't matter
1303 menu.pageUp();
1304
1305 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1306 expect(menu.shownItem(0).active()).toBe(false);
1307 expect(menu.shownItem(1).active()).toBe(false);
1308 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1309 expect(menu.shownItem(2).active()).toBe(false);
1310 expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum');
1311 });
1312
Akron6ed13992016-05-23 18:06:05 +02001313 it('should scroll to a chosen value', function () {
Akron37513a62015-11-17 01:07:11 +01001314 var menu = KorAP.OwnMenu.create(demolist);
1315 menu.limit(3);
Akron6ed13992016-05-23 18:06:05 +02001316
1317 // Choose value 1
1318 expect(menu.show(1)).toBe(true);
1319
1320 expect(menu.shownItem(0).active()).toBe(false);
1321 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1322 expect(menu.shownItem(1).active()).toBe(true);
1323 expect(menu.shownItem(2).active()).toBe(false);
1324 expect(menu.shownItem(3)).toBe(undefined);
1325
1326 // Choose value 2
1327 expect(menu.show(2)).toBe(true);
1328
1329 expect(menu.shownItem(0).active()).toBe(false);
1330 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1331 expect(menu.shownItem(1).active()).toBe(false);
1332 expect(menu.shownItem(2).active()).toBe(true);
1333 expect(menu.shownItem(3)).toBe(undefined);
1334
Akron37513a62015-11-17 01:07:11 +01001335 });
1336
Nils Diewald7148c6f2015-05-04 15:07:53 +00001337 xit('should highlight a chosen value');
Akron6ed13992016-05-23 18:06:05 +02001338 xit('should move the viewport to active, if active is not in the viewport');
Nils Diewald7148c6f2015-05-04 15:07:53 +00001339 });
1340
Akron47c086c2016-05-18 21:22:06 +02001341
1342
1343
Nils Diewald7148c6f2015-05-04 15:07:53 +00001344 describe('KorAP.Prefix', function () {
1345 it('should be initializable', function () {
1346 var p = prefixClass.create();
1347 expect(p.element().classList.contains('pref')).toBeTruthy();
1348 expect(p.isSet()).not.toBeTruthy();
1349
1350/*
1351 expect(mi.lcField()).toEqual(' baum');
1352*/
1353
1354 });
1355
1356 it('should be modifiable', function () {
1357 var p = prefixClass.create();
1358 expect(p.value()).toEqual('');
1359 expect(p.element().firstChild).toBeNull();
1360
1361 // Set string
1362 expect(p.value('Test')).toEqual('Test');
1363 expect(p.value()).toEqual('Test');
1364 expect(p.element().firstChild.nodeValue).toEqual('Test');
1365
1366 // Add string
1367 expect(p.add('ified')).toEqual('Testified');
1368 expect(p.value()).toEqual('Testified');
1369 expect(p.element().firstChild.nodeValue).toEqual('Testified');
1370
1371 // Clear string
1372 p.clear();
1373 expect(p.value()).toEqual('');
1374 expect(p.element().firstChild).toBeNull();
1375
1376 // Set string
1377 expect(p.value('Test')).toEqual('Test');
1378 expect(p.value()).toEqual('Test');
1379 expect(p.element().firstChild.nodeValue).toEqual('Test');
1380
1381 expect(p.chop()).toEqual('Tes');
1382 expect(p.value()).toEqual('Tes');
1383 expect(p.element().firstChild.nodeValue).toEqual('Tes');
1384
1385 expect(p.chop()).toEqual('Te');
1386 expect(p.value()).toEqual('Te');
1387 expect(p.element().firstChild.nodeValue).toEqual('Te');
1388
1389 expect(p.chop()).toEqual('T');
1390 expect(p.value()).toEqual('T');
1391 expect(p.element().firstChild.nodeValue).toEqual('T');
1392
1393 expect(p.chop()).toEqual('');
1394 expect(p.value()).toEqual('');
1395 expect(p.element().firstChild).toBeNull();
1396 });
1397
1398 it('should be activatable', function () {
1399 var p = prefixClass.create();
1400 expect(p.value()).toEqual('');
1401 expect(p.element().firstChild).toBeNull();
1402
1403 expect(p.value('Test')).toEqual('Test');
1404 expect(p.element().firstChild.nodeValue).toEqual('Test');
1405
1406 expect(p.active()).not.toBeTruthy();
1407 expect(p.element().classList.contains('active')).not.toBeTruthy();
1408
1409 p.active(true);
1410 expect(p.active()).toBeTruthy();
1411 expect(p.element().classList.contains('active')).toBeTruthy();
1412 });
Nils Diewaldfda29d92015-01-22 17:28:01 +00001413 });
Akronc7448732016-04-27 14:06:58 +02001414
1415 describe('KorAP.LengthField', function () {
1416 it('should be initializable', function () {
1417 var l = lengthFieldClass.create();
1418 expect(l.element().classList.contains('lengthField')).toBeTruthy();
1419 expect(l.element().children.length).toEqual(0);
1420 });
1421
1422 it('should be extensible', function () {
1423 var l = lengthFieldClass.create();
Akron1ff3ac22016-04-28 16:30:45 +02001424 l.add(['Baum']);
Akronc7448732016-04-27 14:06:58 +02001425 expect(l.element().children.length).toEqual(1);
1426 expect(l.element().children[0].nodeName).toEqual('SPAN');
Akron1ff3ac22016-04-28 16:30:45 +02001427 expect(l.element().children[0].textContent).toEqual('Baum--');
1428 l.add(['Fragezeichen']);
Akronc7448732016-04-27 14:06:58 +02001429 expect(l.element().children.length).toEqual(2);
1430 expect(l.element().children[1].nodeName).toEqual('SPAN');
Akron1ff3ac22016-04-28 16:30:45 +02001431 expect(l.element().children[1].textContent).toEqual('Fragezeichen--');
Akronc7448732016-04-27 14:06:58 +02001432 });
1433
1434 it('should be correctly initializable', function () {
1435 var list = [
1436 ["Constituency"],
1437 ["Lemma"],
1438 ["Morphology"],
1439 ["Part-of-Speech"],
1440 ["Syntax"]
1441 ];
1442
1443 var menu = KorAP.OwnMenu.create(list);
1444
1445 expect(menu.lengthField().element().children.length).toEqual(5);
1446 });
1447 });
Akronf86eaea2016-05-13 18:02:27 +02001448
1449 describe('KorAP.Slider', function () {
Akron97752a72016-05-25 14:43:07 +02001450
1451 var demolonglist = [
1452 ['Titel', 'title'],
1453 ['Untertitel', 'subTitle'],
1454 ['Veröffentlichungsdatum', 'pubDate'],
1455 ['Länge', 'length'],
1456 ['Autor', 'author'],
1457 ['Genre', 'genre'],
1458 ['corpusID', 'corpusID'],
1459 ['docID', 'docID'],
1460 ['textID', 'textID'],
1461 ];
1462
Akron6ed13992016-05-23 18:06:05 +02001463 it('should correctly be initializable', function () {
Akronf86eaea2016-05-13 18:02:27 +02001464 var list = [
1465 ["Constituency"],
1466 ["Lemma"],
1467 ["Morphology"],
1468 ["Part-of-Speech"],
1469 ["Syntax"]
1470 ];
1471
1472 var menu = KorAP.OwnMenu.create(list);
1473
1474 menu._firstActive = true;
1475 menu.limit(3);
1476
1477 expect(menu.show()).toBe(true);
1478
1479 expect(menu.shownItem(0).active()).toBe(true);
1480 expect(menu.shownItem(1).active()).toBe(false);
1481 expect(menu.shownItem(2).active()).toBe(false);
1482 expect(menu.slider().offset()).toEqual(0);
1483 expect(menu.position).toEqual(0);
Akron6ed13992016-05-23 18:06:05 +02001484 });
1485
1486 it('should correctly move on arrow keys', function () {
1487 var list = [
1488 ["Constituency"],
1489 ["Lemma"],
1490 ["Morphology"],
1491 ["Part-of-Speech"],
1492 ["Syntax"]
1493 ];
1494
1495 var menu = KorAP.OwnMenu.create(list);
1496
1497 menu._firstActive = true;
1498 menu.limit(3);
1499
1500 expect(menu.show()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +02001501
1502 menu.next();
1503 expect(menu.shownItem(0).active()).toBe(false);
1504 expect(menu.shownItem(1).active()).toBe(true);
1505 expect(menu.shownItem(2).active()).toBe(false);
1506 expect(menu.slider().offset()).toEqual(0);
1507 expect(menu.position).toEqual(1);
1508
1509 menu.next();
1510 expect(menu.shownItem(0).active()).toBe(false);
1511 expect(menu.shownItem(1).active()).toBe(false);
1512 expect(menu.shownItem(2).active()).toBe(true);
1513 expect(menu.slider().offset()).toEqual(0);
1514 expect(menu.position).toEqual(2);
1515
1516 menu.next();
1517 expect(menu.shownItem(0).active()).toBe(false);
1518 expect(menu.shownItem(1).active()).toBe(false);
1519 expect(menu.shownItem(2).active()).toBe(true);
1520 expect(menu.slider().offset()).toEqual(1);
1521 expect(menu.position).toEqual(3);
1522
1523 menu.next();
1524 expect(menu.shownItem(0).active()).toBe(false);
1525 expect(menu.shownItem(1).active()).toBe(false);
1526 expect(menu.shownItem(2).active()).toBe(true);
1527 expect(menu.slider().offset()).toEqual(2);
1528 expect(menu.position).toEqual(4);
1529
1530 menu.next();
1531 expect(menu.shownItem(0).active()).toBe(true);
1532 expect(menu.shownItem(1).active()).toBe(false);
1533 expect(menu.shownItem(2).active()).toBe(false);
1534 expect(menu.slider().offset()).toEqual(0);
1535 expect(menu.position).toEqual(0);
1536
1537 expect(menu.slider()._slider.style.height).toEqual('60%');
Akron6ed13992016-05-23 18:06:05 +02001538 });
Akronf86eaea2016-05-13 18:02:27 +02001539
Akron97752a72016-05-25 14:43:07 +02001540 it('should correctly resize on prefixing', function () {
1541 var menu = KorAP.OwnMenu.create(demolonglist);
1542 menu._firstActive = true;
1543 menu.limit(3);
1544
1545 expect(menu.show()).toBe(true);
1546 expect(menu.slider().offset()).toEqual(0);
1547 expect(menu.slider().length()).toEqual(9);
1548
1549 expect(menu.prefix("e").show()).toBe(true);
1550 expect(menu.slider().length()).toEqual(6);
1551
1552 expect(menu.prefix("el").show()).toBe(true);
1553 expect(menu.slider().length()).toEqual(2);
1554
1555 expect(menu.prefix("e").show()).toBe(true);
1556 expect(menu.slider().length()).toEqual(6);
1557
1558 expect(menu.prefix("").show()).toBe(true);
1559 expect(menu.slider().length()).toEqual(9);
1560 });
1561
1562
Akron6ed13992016-05-23 18:06:05 +02001563 it('should correctly move the list on mousemove', function () {
1564 var list = [
1565 ["Constituency"],
1566 ["Lemma"],
1567 ["Morphology"],
1568 ["Part-of-Speech"],
1569 ["Syntax"]
1570 ];
1571
1572 var menu = KorAP.OwnMenu.create(list);
1573
1574 menu._firstActive = true;
1575 menu.limit(3);
1576
1577 expect(menu.show()).toBe(true);
1578
1579 expect(menu.shownItem(0).active()).toBe(true);
1580 expect(menu.shownItem(1).active()).toBe(false);
1581 expect(menu.shownItem(2).active()).toBe(false);
1582 expect(menu.slider().offset()).toEqual(0);
1583
1584 // This will normally be done on
1585 menu.slider()._rulerHeight = 100;
1586 menu.slider()._sliderHeight = 40;
1587 expect(menu.slider().length()).toEqual(5);
1588
1589 menu.slider().movetoRel(10);
1590 expect(menu.slider().offset()).toEqual(0);
1591 expect(menu.shownItem(0).active()).toBe(true);
1592 expect(menu.shownItem(0).lcField()).toEqual(' constituency');
1593 menu.slider().movetoRel(24);
1594 expect(menu.slider().offset()).toEqual(0);
1595 menu.slider().movetoRel(25);
1596 expect(menu.slider().offset()).toEqual(0);
1597
1598 menu.slider().movetoRel(30);
1599 expect(menu.slider().offset()).toEqual(1);
1600 menu.slider().movetoRel(59);
1601 expect(menu.slider().offset()).toEqual(1);
1602 expect(menu.shownItem(0).active()).toBe(false);
1603 expect(menu.shownItem(0).lcField()).toEqual(' lemma');
1604
1605 // Everything > 60 is offset 2
1606 menu.slider().movetoRel(60);
1607 expect(menu.slider().offset()).toEqual(2);
1608 menu.slider().movetoRel(180);
1609 expect(menu.slider().offset()).toEqual(2);
1610 expect(menu.shownItem(0).active()).toBe(false);
1611 expect(menu.shownItem(0).lcField()).toEqual(' morphology');
Akron5a1f5bb2016-05-23 22:00:39 +02001612
1613 expect(menu.shownItem(1).active()).toBe(false);
1614 expect(menu.shownItem(2).active()).toBe(false);
1615
1616 // When the active cursor moves again - scroll to viewport
1617 // cursor is before viewport
1618 menu.next();
1619 expect(menu.shownItem(0).active()).toBe(true);
1620 expect(menu.shownItem(0).lcField()).toEqual(' lemma');
1621 expect(menu.shownItem(1).active()).toBe(false);
1622 expect(menu.shownItem(2).active()).toBe(false);
1623
1624 menu.next();
1625 menu.next();
1626 expect(menu.shownItem(0).active()).toBe(false);
1627 expect(menu.shownItem(0).lcField()).toEqual(' lemma');
1628 expect(menu.shownItem(1).active()).toBe(false);
1629 expect(menu.shownItem(1).lcField()).toEqual(' morphology');
1630 expect(menu.shownItem(2).active()).toBe(true);
1631 expect(menu.shownItem(2).lcField()).toEqual(' part-of-speech');
1632
1633 menu.slider().movetoRel(0);
1634 expect(menu.slider().offset()).toEqual(0);
1635 expect(menu.shownItem(0).active()).toBe(false);
1636 expect(menu.shownItem(0).lcField()).toEqual(' constituency');
1637 expect(menu.shownItem(1).active()).toBe(false);
1638 expect(menu.shownItem(1).lcField()).toEqual(' lemma');
1639 expect(menu.shownItem(2).active()).toBe(false);
1640 expect(menu.shownItem(2).lcField()).toEqual(' morphology');
1641
1642 // cursor is after viewport
1643 menu.next();
1644 expect(menu.slider().offset()).toEqual(2);
1645 expect(menu.shownItem(0).active()).toBe(false);
1646 expect(menu.shownItem(0).lcField()).toEqual(' morphology');
1647 expect(menu.shownItem(1).active()).toBe(false);
1648 expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech');
1649 expect(menu.shownItem(2).active()).toBe(true);
1650 expect(menu.shownItem(2).lcField()).toEqual(' syntax');
1651
1652 menu.slider().movetoRel(0);
1653 expect(menu.slider().offset()).toEqual(0);
1654 expect(menu.shownItem(0).active()).toBe(false);
1655 expect(menu.shownItem(0).lcField()).toEqual(' constituency');
1656 expect(menu.shownItem(1).active()).toBe(false);
1657 expect(menu.shownItem(1).lcField()).toEqual(' lemma');
1658 expect(menu.shownItem(2).active()).toBe(false);
1659 expect(menu.shownItem(2).lcField()).toEqual(' morphology');
1660
1661 menu.prev();
1662 expect(menu.slider().offset()).toEqual(2);
1663 expect(menu.shownItem(0).lcField()).toEqual(' morphology');
1664 expect(menu.shownItem(0).active()).toBe(false);
1665 expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech');
1666 expect(menu.shownItem(1).active()).toBe(true);
1667 expect(menu.shownItem(2).lcField()).toEqual(' syntax');
1668 expect(menu.shownItem(2).active()).toBe(false);
1669
1670 menu.prev();
1671 menu.prev();
1672 expect(menu.slider().offset()).toEqual(1);
1673 expect(menu.shownItem(0).lcField()).toEqual(' lemma');
1674 expect(menu.shownItem(0).active()).toBe(true);
1675 expect(menu.shownItem(1).lcField()).toEqual(' morphology');
1676 expect(menu.shownItem(1).active()).toBe(false);
1677 expect(menu.shownItem(2).lcField()).toEqual(' part-of-speech');
1678 expect(menu.shownItem(2).active()).toBe(false);
1679
1680 menu.slider().movetoRel(100);
1681 expect(menu.slider().offset()).toEqual(2);
1682 expect(menu.shownItem(0).lcField()).toEqual(' morphology');
1683 expect(menu.shownItem(0).active()).toBe(false);
1684 expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech');
1685 expect(menu.shownItem(1).active()).toBe(false);
1686 expect(menu.shownItem(2).lcField()).toEqual(' syntax');
1687 expect(menu.shownItem(2).active()).toBe(false);
1688
1689 menu.prev();
1690 expect(menu.slider().offset()).toEqual(0);
1691 expect(menu.shownItem(0).lcField()).toEqual(' constituency');
1692 expect(menu.shownItem(0).active()).toBe(true);
1693 expect(menu.shownItem(1).lcField()).toEqual(' lemma');
1694 expect(menu.shownItem(1).active()).toBe(false);
1695 expect(menu.shownItem(2).lcField()).toEqual(' morphology');
1696 expect(menu.shownItem(2).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +02001697 });
1698 });
Nils Diewaldfda29d92015-01-22 17:28:01 +00001699});