blob: 972f3850dee381f67a5a9c9e3f1fa7a4552a3415 [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);
Akron5240b8c2016-05-20 09:17:41 +0200398 expect(menu.unshow()).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
Akron6ed13992016-05-23 18:06:05 +0200770 it('should choose prefix with failing prefix', 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);
774 expect(menu.shownItem(0)).toBeUndefined();
775 expect(menu._prefix.active()).toBe(true);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000776 });
777
Akron37513a62015-11-17 01:07:11 +0100778
Nils Diewald7c8ced22015-04-15 19:21:00 +0000779 it('should be navigatable with prefix', function () {
780 var menu = KorAP.HintMenu.create("cnx/", demolist);
Akronc1457bf2015-06-11 19:24:00 +0200781 menu._firstActive = true;
782
Nils Diewald7c8ced22015-04-15 19:21:00 +0000783 menu.limit(3);
784
785 expect(menu.show()).toBe(true);
786 expect(menu.prefix()).toEqual("");
787
788 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200789 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000790 expect(menu.shownItem(0).active()).toBe(true);
791 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200792 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000793 expect(menu.shownItem(1).active()).toBe(false);
794 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200795 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000796 expect(menu.shownItem(2).active()).toBe(false);
797 expect(menu.shownItem(3)).toBe(undefined);
798
799 menu._prefix.add('a');
800 expect(menu.show()).toBe(true);
801 expect(menu.prefix()).toEqual("a");
802 expect(menu.shownItem(0).name()).toEqual("Autor");
Akronf86eaea2016-05-13 18:02:27 +0200803 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000804
805 menu._prefix.add('u');
806 expect(menu.show()).toBe(true);
807 expect(menu.prefix()).toEqual("au");
808 expect(menu.shownItem(0).name()).toEqual("Autor");
Akronf86eaea2016-05-13 18:02:27 +0200809 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong><mark>Au</mark>tor</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000810
Nils Diewald7148c6f2015-05-04 15:07:53 +0000811 menu._prefix.chop();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000812 expect(menu.show()).toBe(true);
813 expect(menu.prefix()).toEqual("a");
814 expect(menu.shownItem(0).name()).toEqual("Autor");
Akronf86eaea2016-05-13 18:02:27 +0200815 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000816
Nils Diewald7148c6f2015-05-04 15:07:53 +0000817 menu._prefix.chop();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000818 expect(menu.show()).toBe(true);
819 expect(menu.prefix()).toEqual("");
820 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200821 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000822 expect(menu.shownItem(0).active()).toBe(true);
823 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200824 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000825 expect(menu.shownItem(1).active()).toBe(false);
826 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200827 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000828 expect(menu.shownItem(2).active()).toBe(false);
829 expect(menu.shownItem(3)).toBe(undefined);
830
831 // Forward
Nils Diewald7148c6f2015-05-04 15:07:53 +0000832 menu._prefix.chop();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000833 expect(menu.show()).toBe(true);
834 expect(menu.prefix()).toEqual("");
835 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200836 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000837 expect(menu.shownItem(0).active()).toBe(true);
838 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200839 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000840 expect(menu.shownItem(1).active()).toBe(false);
841 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200842 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000843 expect(menu.shownItem(2).active()).toBe(false);
844
845 // Forward
846 menu.next();
847 expect(menu.prefix()).toEqual("");
848 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200849 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000850 expect(menu.shownItem(0).active()).toBe(false);
851 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200852 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000853 expect(menu.shownItem(1).active()).toBe(true);
854 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200855 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000856 expect(menu.shownItem(2).active()).toBe(false);
857 expect(menu.shownItem(3)).toBe(undefined);
858
859 // Forward
860 menu.next();
861 expect(menu.prefix()).toEqual("");
862 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200863 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000864 expect(menu.shownItem(0).active()).toBe(false);
865 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200866 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000867 expect(menu.shownItem(1).active()).toBe(false);
868 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200869 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000870 expect(menu.shownItem(2).active()).toBe(true);
871 expect(menu.shownItem(3)).toBe(undefined);
872
873 // Forward
874 menu.next();
875 expect(menu.prefix()).toEqual("");
876 expect(menu.shownItem(0).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200877 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Untertitel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000878 expect(menu.shownItem(0).active()).toBe(false);
879 expect(menu.shownItem(1).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200880 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000881 expect(menu.shownItem(1).active()).toBe(false);
882 expect(menu.shownItem(2).name()).toEqual("Länge");
Akronf86eaea2016-05-13 18:02:27 +0200883 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Länge</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000884 expect(menu.shownItem(2).active()).toBe(true);
885 expect(menu.shownItem(3)).toBe(undefined);
886
887 // Forward
888 menu.next();
889 expect(menu.prefix()).toEqual("");
890 expect(menu.shownItem(0).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200891 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000892 expect(menu.shownItem(0).active()).toBe(false);
893 expect(menu.shownItem(1).name()).toEqual("Länge");
Akronf86eaea2016-05-13 18:02:27 +0200894 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Länge</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000895 expect(menu.shownItem(1).active()).toBe(false);
896 expect(menu.shownItem(2).name()).toEqual("Autor");
Akronf86eaea2016-05-13 18:02:27 +0200897 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Autor</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000898 expect(menu.shownItem(2).active()).toBe(true);
899 expect(menu.shownItem(3)).toBe(undefined);
900
901 // Forward
902 menu.next();
903 expect(menu.prefix()).toEqual("");
904 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200905 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000906 expect(menu.shownItem(0).active()).toBe(true);
907 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200908 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000909 expect(menu.shownItem(1).active()).toBe(false);
910 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200911 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000912 expect(menu.shownItem(2).active()).toBe(false);
913 });
914
915
916 it('should be navigatable with a prefix (1)', function () {
917 var menu = KorAP.HintMenu.create("cnx/", demolist);
Akronc1457bf2015-06-11 19:24:00 +0200918 menu._firstActive = true;
919
Nils Diewald7c8ced22015-04-15 19:21:00 +0000920 menu.limit(3);
921
922 expect(menu.show()).toBe(true);
923 expect(menu.prefix()).toEqual("");
924
925 menu.prefix('el');
926 expect(menu.show()).toBe(true);
927
928 expect(menu.prefix()).toEqual("el");
929 expect(menu._prefix.active()).toEqual(false);
930 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200931 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000932 expect(menu.shownItem(0).active()).toBe(true);
933 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200934 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000935 expect(menu.shownItem(1).active()).toBe(false);
936 expect(menu.shownItem(2)).toBe(undefined);
937
938 // Forward
939 menu.next();
940 expect(menu.prefix()).toEqual("el");
941 expect(menu._prefix.active()).toEqual(false);
942 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200943 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000944 expect(menu.shownItem(0).active()).toBe(false);
945 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200946 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000947 expect(menu.shownItem(1).active()).toBe(true);
948 expect(menu.shownItem(2)).toBe(undefined);
949
950 // Forward
951 menu.next();
952 expect(menu.prefix()).toEqual("el");
953 expect(menu._prefix.active()).toEqual(true);
954 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200955 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000956 expect(menu.shownItem(0).active()).toBe(false);
957 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200958 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000959 expect(menu.shownItem(1).active()).toBe(false);
960 expect(menu.shownItem(2)).toBe(undefined);
961
962 // Backward
963 menu.prev();
964 expect(menu.prefix()).toEqual("el");
965 expect(menu._prefix.active()).toEqual(false);
966 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200967 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000968 expect(menu.shownItem(0).active()).toBe(false);
969
970 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200971 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000972 expect(menu.shownItem(1).active()).toBe(true);
973 expect(menu.shownItem(2)).toBe(undefined);
974 });
975
976
977 it('should be navigatable with a prefix (2)', function () {
978 var menu = KorAP.HintMenu.create("cnx/", demolist);
Akronc1457bf2015-06-11 19:24:00 +0200979 menu._firstActive = true;
980
Nils Diewald7c8ced22015-04-15 19:21:00 +0000981 menu.limit(3);
982 expect(menu.show()).toBe(true);
983 expect(menu.prefix()).toEqual("");
984 menu.prefix('el');
985 expect(menu.show()).toBe(true);
986
987 expect(menu.prefix()).toEqual("el");
988 expect(menu._prefix.active()).toEqual(false);
989 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200990 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000991 expect(menu.shownItem(0).active()).toBe(true);
992 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200993 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000994 expect(menu.shownItem(1).active()).toBe(false);
995 expect(menu.shownItem(2)).toBe(undefined);
996
997 // Backward
998 menu.prev();
999 expect(menu._prefix.active()).toEqual(true);
1000
1001 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +02001002 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001003 expect(menu.shownItem(0).active()).toBe(false);
1004
1005 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +02001006 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001007 expect(menu.shownItem(1).active()).toBe(false);
1008 expect(menu.shownItem(2)).toBe(undefined);
1009
1010 // Backward
1011 menu.prev();
1012 expect(menu._prefix.active()).toEqual(false);
1013 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +02001014 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001015 expect(menu.shownItem(0).active()).toBe(false);
1016 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +02001017 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001018 expect(menu.shownItem(1).active()).toBe(true);
1019 expect(menu.shownItem(2)).toBe(undefined);
1020 });
1021
1022 it('should be navigatable with a prefix (3)', function () {
1023 var menu = KorAP.HintMenu.create("cnx/", demolist);
Akronc1457bf2015-06-11 19:24:00 +02001024 menu._firstActive = true;
Nils Diewald7c8ced22015-04-15 19:21:00 +00001025 menu.limit(3);
1026 expect(menu.show()).toBe(true);
1027 expect(menu.prefix()).toEqual("");
1028 menu.prefix('el');
1029 expect(menu.show()).toBe(true);
1030
1031 expect(menu.prefix()).toEqual("el");
1032 expect(menu._prefix.active()).toEqual(false);
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(true);
1036 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +02001037 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001038 expect(menu.shownItem(1).active()).toBe(false);
1039 expect(menu.shownItem(2)).toBe(undefined);
1040
1041 // Backward
1042 menu.prev();
1043 expect(menu._prefix.active()).toEqual(true);
1044 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +02001045 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001046 expect(menu.shownItem(0).active()).toBe(false);
1047 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +02001048 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001049 expect(menu.shownItem(1).active()).toBe(false);
1050 expect(menu.shownItem(2)).toBe(undefined);
1051
1052
1053 // Forward
1054 menu.next();
1055 expect(menu.prefix()).toEqual("el");
1056 expect(menu._prefix.active()).toEqual(false);
1057 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +02001058 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001059 expect(menu.shownItem(0).active()).toBe(true);
1060 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +02001061 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001062 expect(menu.shownItem(1).active()).toBe(false);
1063 expect(menu.shownItem(2)).toBe(undefined);
1064
1065 });
1066
Akron47c086c2016-05-18 21:22:06 +02001067 it('should show screens by offset', function () {
1068 var menu = KorAP.HintMenu.create('cnx/', demolist);
1069 menu.limit(3);
1070 expect(menu.show()).toBe(true);
1071
1072 expect(menu.shownItem(0).active()).toBe(false);
1073 expect(menu.shownItem(1).active()).toBe(false);
1074 expect(menu.shownItem(2).active()).toBe(false);
1075
Akron5240b8c2016-05-20 09:17:41 +02001076 // Highlight the first entry
Akron47c086c2016-05-18 21:22:06 +02001077 menu.next();
1078
1079 expect(menu.shownItem(0).active()).toBe(true);
1080 expect(menu.shownItem(1).active()).toBe(false);
1081 expect(menu.shownItem(2).active()).toBe(false);
1082
Akron5240b8c2016-05-20 09:17:41 +02001083 // Highlight the second entry
Akron47c086c2016-05-18 21:22:06 +02001084 menu.next();
1085
1086 expect(menu.shownItem(0).active()).toBe(false);
1087 expect(menu.shownItem(1).active()).toBe(true);
1088 expect(menu.shownItem(2).active()).toBe(false);
1089 expect(menu.shownItem(3)).toBe(undefined);
1090
1091 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1092 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
1093
Akron5240b8c2016-05-20 09:17:41 +02001094 // Move to first screen
Akron47c086c2016-05-18 21:22:06 +02001095 menu.screen(0);
Akron5240b8c2016-05-20 09:17:41 +02001096 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1097 expect(menu.shownItem(1).lcField()).toEqual(' untertitel');
Akron47c086c2016-05-18 21:22:06 +02001098 expect(menu.shownItem(0).active()).toBe(false);
1099 expect(menu.shownItem(1).active()).toBe(true);
1100 expect(menu.shownItem(2).active()).toBe(false);
1101 expect(menu.shownItem(3)).toBe(undefined);
Akroncb351d62016-05-19 23:10:33 +02001102
Akron5240b8c2016-05-20 09:17:41 +02001103 // Move to second screen
Akron47c086c2016-05-18 21:22:06 +02001104 menu.screen(1);
Akron5240b8c2016-05-20 09:17:41 +02001105 expect(menu.shownItem(0).lcField()).toEqual(' untertitel');
Akron47c086c2016-05-18 21:22:06 +02001106 expect(menu.shownItem(0).active()).toBe(true);
Akron47c086c2016-05-18 21:22:06 +02001107 expect(menu.shownItem(1).active()).toBe(false);
1108 expect(menu.shownItem(2).active()).toBe(false);
Akron5240b8c2016-05-20 09:17:41 +02001109 expect(menu.shownItem(3)).toBe(undefined);
1110
1111 menu.screen(2);
1112 expect(menu.shownItem(0).lcField()).toEqual(' veröffentlichungsdatum');
1113 expect(menu.shownItem(0).active()).toBe(false);
1114 expect(menu.shownItem(1).active()).toBe(false);
1115 expect(menu.shownItem(2).active()).toBe(false);
1116 expect(menu.shownItem(3)).toBe(undefined);
1117
1118 menu.screen(1);
1119 expect(menu.shownItem(0).lcField()).toEqual(' untertitel');
1120 expect(menu.shownItem(0).active()).toBe(true);
1121 expect(menu.shownItem(1).active()).toBe(false);
1122 expect(menu.shownItem(2).active()).toBe(false);
1123 expect(menu.shownItem(3)).toBe(undefined);
Akron47c086c2016-05-18 21:22:06 +02001124 });
1125
Akron6ed13992016-05-23 18:06:05 +02001126 it('should show screens by offset when prefixed', function () {
1127 var menu = KorAP.HintMenu.create('cnx/', demolist);
1128 menu.limit(3);
1129 expect(menu.prefix("e").show()).toBe(true);
1130 expect(menu.shownItem(0).active()).toBe(false);
1131 expect(menu.shownItem(1).active()).toBe(false);
1132 expect(menu.shownItem(2).active()).toBe(false);
1133
1134 expect(menu.shownItem(0).element().innerHTML).toEqual('<strong>Tit<mark>e</mark>l</strong>');
1135 menu.screen(1);
1136 expect(menu.shownItem(0).element().innerHTML).toEqual('<strong>Unt<mark>e</mark>rtit<mark>e</mark>l</strong>');
1137 });
1138
Akron47c086c2016-05-18 21:22:06 +02001139
Nils Diewald7c8ced22015-04-15 19:21:00 +00001140 xit('should be page downable');
1141 xit('should be page upable');
1142
Akron6ed13992016-05-23 18:06:05 +02001143 it('should scroll to a chosen value', function () {
Akron37513a62015-11-17 01:07:11 +01001144 var menu = KorAP.OwnMenu.create(demolist);
1145 menu.limit(3);
Akron6ed13992016-05-23 18:06:05 +02001146
1147 // Choose value 1
1148 expect(menu.show(1)).toBe(true);
1149
1150 expect(menu.shownItem(0).active()).toBe(false);
1151 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1152 expect(menu.shownItem(1).active()).toBe(true);
1153 expect(menu.shownItem(2).active()).toBe(false);
1154 expect(menu.shownItem(3)).toBe(undefined);
1155
1156 // Choose value 2
1157 expect(menu.show(2)).toBe(true);
1158
1159 expect(menu.shownItem(0).active()).toBe(false);
1160 expect(menu.shownItem(0).lcField()).toEqual(' titel');
1161 expect(menu.shownItem(1).active()).toBe(false);
1162 expect(menu.shownItem(2).active()).toBe(true);
1163 expect(menu.shownItem(3)).toBe(undefined);
1164
Akron37513a62015-11-17 01:07:11 +01001165 });
1166
Nils Diewald7148c6f2015-05-04 15:07:53 +00001167 xit('should highlight a chosen value');
Akron6ed13992016-05-23 18:06:05 +02001168
1169 xit('should move the viewport to active, if active is not in the viewport');
Nils Diewald7148c6f2015-05-04 15:07:53 +00001170 });
1171
Akron47c086c2016-05-18 21:22:06 +02001172
1173
1174
Nils Diewald7148c6f2015-05-04 15:07:53 +00001175 describe('KorAP.Prefix', function () {
1176 it('should be initializable', function () {
1177 var p = prefixClass.create();
1178 expect(p.element().classList.contains('pref')).toBeTruthy();
1179 expect(p.isSet()).not.toBeTruthy();
1180
1181/*
1182 expect(mi.lcField()).toEqual(' baum');
1183*/
1184
1185 });
1186
1187 it('should be modifiable', function () {
1188 var p = prefixClass.create();
1189 expect(p.value()).toEqual('');
1190 expect(p.element().firstChild).toBeNull();
1191
1192 // Set string
1193 expect(p.value('Test')).toEqual('Test');
1194 expect(p.value()).toEqual('Test');
1195 expect(p.element().firstChild.nodeValue).toEqual('Test');
1196
1197 // Add string
1198 expect(p.add('ified')).toEqual('Testified');
1199 expect(p.value()).toEqual('Testified');
1200 expect(p.element().firstChild.nodeValue).toEqual('Testified');
1201
1202 // Clear string
1203 p.clear();
1204 expect(p.value()).toEqual('');
1205 expect(p.element().firstChild).toBeNull();
1206
1207 // Set string
1208 expect(p.value('Test')).toEqual('Test');
1209 expect(p.value()).toEqual('Test');
1210 expect(p.element().firstChild.nodeValue).toEqual('Test');
1211
1212 expect(p.chop()).toEqual('Tes');
1213 expect(p.value()).toEqual('Tes');
1214 expect(p.element().firstChild.nodeValue).toEqual('Tes');
1215
1216 expect(p.chop()).toEqual('Te');
1217 expect(p.value()).toEqual('Te');
1218 expect(p.element().firstChild.nodeValue).toEqual('Te');
1219
1220 expect(p.chop()).toEqual('T');
1221 expect(p.value()).toEqual('T');
1222 expect(p.element().firstChild.nodeValue).toEqual('T');
1223
1224 expect(p.chop()).toEqual('');
1225 expect(p.value()).toEqual('');
1226 expect(p.element().firstChild).toBeNull();
1227 });
1228
1229 it('should be activatable', function () {
1230 var p = prefixClass.create();
1231 expect(p.value()).toEqual('');
1232 expect(p.element().firstChild).toBeNull();
1233
1234 expect(p.value('Test')).toEqual('Test');
1235 expect(p.element().firstChild.nodeValue).toEqual('Test');
1236
1237 expect(p.active()).not.toBeTruthy();
1238 expect(p.element().classList.contains('active')).not.toBeTruthy();
1239
1240 p.active(true);
1241 expect(p.active()).toBeTruthy();
1242 expect(p.element().classList.contains('active')).toBeTruthy();
1243 });
Nils Diewaldfda29d92015-01-22 17:28:01 +00001244 });
Akronc7448732016-04-27 14:06:58 +02001245
1246 describe('KorAP.LengthField', function () {
1247 it('should be initializable', function () {
1248 var l = lengthFieldClass.create();
1249 expect(l.element().classList.contains('lengthField')).toBeTruthy();
1250 expect(l.element().children.length).toEqual(0);
1251 });
1252
1253 it('should be extensible', function () {
1254 var l = lengthFieldClass.create();
Akron1ff3ac22016-04-28 16:30:45 +02001255 l.add(['Baum']);
Akronc7448732016-04-27 14:06:58 +02001256 expect(l.element().children.length).toEqual(1);
1257 expect(l.element().children[0].nodeName).toEqual('SPAN');
Akron1ff3ac22016-04-28 16:30:45 +02001258 expect(l.element().children[0].textContent).toEqual('Baum--');
1259 l.add(['Fragezeichen']);
Akronc7448732016-04-27 14:06:58 +02001260 expect(l.element().children.length).toEqual(2);
1261 expect(l.element().children[1].nodeName).toEqual('SPAN');
Akron1ff3ac22016-04-28 16:30:45 +02001262 expect(l.element().children[1].textContent).toEqual('Fragezeichen--');
Akronc7448732016-04-27 14:06:58 +02001263 });
1264
1265 it('should be correctly initializable', function () {
1266 var list = [
1267 ["Constituency"],
1268 ["Lemma"],
1269 ["Morphology"],
1270 ["Part-of-Speech"],
1271 ["Syntax"]
1272 ];
1273
1274 var menu = KorAP.OwnMenu.create(list);
1275
1276 expect(menu.lengthField().element().children.length).toEqual(5);
1277 });
1278 });
Akronf86eaea2016-05-13 18:02:27 +02001279
1280 describe('KorAP.Slider', function () {
Akron6ed13992016-05-23 18:06:05 +02001281 it('should correctly be initializable', function () {
Akronf86eaea2016-05-13 18:02:27 +02001282 var list = [
1283 ["Constituency"],
1284 ["Lemma"],
1285 ["Morphology"],
1286 ["Part-of-Speech"],
1287 ["Syntax"]
1288 ];
1289
1290 var menu = KorAP.OwnMenu.create(list);
1291
1292 menu._firstActive = true;
1293 menu.limit(3);
1294
1295 expect(menu.show()).toBe(true);
1296
1297 expect(menu.shownItem(0).active()).toBe(true);
1298 expect(menu.shownItem(1).active()).toBe(false);
1299 expect(menu.shownItem(2).active()).toBe(false);
1300 expect(menu.slider().offset()).toEqual(0);
1301 expect(menu.position).toEqual(0);
Akron6ed13992016-05-23 18:06:05 +02001302 });
1303
1304 it('should correctly move on arrow keys', function () {
1305 var list = [
1306 ["Constituency"],
1307 ["Lemma"],
1308 ["Morphology"],
1309 ["Part-of-Speech"],
1310 ["Syntax"]
1311 ];
1312
1313 var menu = KorAP.OwnMenu.create(list);
1314
1315 menu._firstActive = true;
1316 menu.limit(3);
1317
1318 expect(menu.show()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +02001319
1320 menu.next();
1321 expect(menu.shownItem(0).active()).toBe(false);
1322 expect(menu.shownItem(1).active()).toBe(true);
1323 expect(menu.shownItem(2).active()).toBe(false);
1324 expect(menu.slider().offset()).toEqual(0);
1325 expect(menu.position).toEqual(1);
1326
1327 menu.next();
1328 expect(menu.shownItem(0).active()).toBe(false);
1329 expect(menu.shownItem(1).active()).toBe(false);
1330 expect(menu.shownItem(2).active()).toBe(true);
1331 expect(menu.slider().offset()).toEqual(0);
1332 expect(menu.position).toEqual(2);
1333
1334 menu.next();
1335 expect(menu.shownItem(0).active()).toBe(false);
1336 expect(menu.shownItem(1).active()).toBe(false);
1337 expect(menu.shownItem(2).active()).toBe(true);
1338 expect(menu.slider().offset()).toEqual(1);
1339 expect(menu.position).toEqual(3);
1340
1341 menu.next();
1342 expect(menu.shownItem(0).active()).toBe(false);
1343 expect(menu.shownItem(1).active()).toBe(false);
1344 expect(menu.shownItem(2).active()).toBe(true);
1345 expect(menu.slider().offset()).toEqual(2);
1346 expect(menu.position).toEqual(4);
1347
1348 menu.next();
1349 expect(menu.shownItem(0).active()).toBe(true);
1350 expect(menu.shownItem(1).active()).toBe(false);
1351 expect(menu.shownItem(2).active()).toBe(false);
1352 expect(menu.slider().offset()).toEqual(0);
1353 expect(menu.position).toEqual(0);
1354
1355 expect(menu.slider()._slider.style.height).toEqual('60%');
Akron6ed13992016-05-23 18:06:05 +02001356 });
Akronf86eaea2016-05-13 18:02:27 +02001357
Akron6ed13992016-05-23 18:06:05 +02001358 it('should correctly move the list on mousemove', function () {
1359 var list = [
1360 ["Constituency"],
1361 ["Lemma"],
1362 ["Morphology"],
1363 ["Part-of-Speech"],
1364 ["Syntax"]
1365 ];
1366
1367 var menu = KorAP.OwnMenu.create(list);
1368
1369 menu._firstActive = true;
1370 menu.limit(3);
1371
1372 expect(menu.show()).toBe(true);
1373
1374 expect(menu.shownItem(0).active()).toBe(true);
1375 expect(menu.shownItem(1).active()).toBe(false);
1376 expect(menu.shownItem(2).active()).toBe(false);
1377 expect(menu.slider().offset()).toEqual(0);
1378
1379 // This will normally be done on
1380 menu.slider()._rulerHeight = 100;
1381 menu.slider()._sliderHeight = 40;
1382 expect(menu.slider().length()).toEqual(5);
1383
1384 menu.slider().movetoRel(10);
1385 expect(menu.slider().offset()).toEqual(0);
1386 expect(menu.shownItem(0).active()).toBe(true);
1387 expect(menu.shownItem(0).lcField()).toEqual(' constituency');
1388 menu.slider().movetoRel(24);
1389 expect(menu.slider().offset()).toEqual(0);
1390 menu.slider().movetoRel(25);
1391 expect(menu.slider().offset()).toEqual(0);
1392
1393 menu.slider().movetoRel(30);
1394 expect(menu.slider().offset()).toEqual(1);
1395 menu.slider().movetoRel(59);
1396 expect(menu.slider().offset()).toEqual(1);
1397 expect(menu.shownItem(0).active()).toBe(false);
1398 expect(menu.shownItem(0).lcField()).toEqual(' lemma');
1399
1400 // Everything > 60 is offset 2
1401 menu.slider().movetoRel(60);
1402 expect(menu.slider().offset()).toEqual(2);
1403 menu.slider().movetoRel(180);
1404 expect(menu.slider().offset()).toEqual(2);
1405 expect(menu.shownItem(0).active()).toBe(false);
1406 expect(menu.shownItem(0).lcField()).toEqual(' morphology');
Akron5a1f5bb2016-05-23 22:00:39 +02001407
1408 expect(menu.shownItem(1).active()).toBe(false);
1409 expect(menu.shownItem(2).active()).toBe(false);
1410
1411 // When the active cursor moves again - scroll to viewport
1412 // cursor is before viewport
1413 menu.next();
1414 expect(menu.shownItem(0).active()).toBe(true);
1415 expect(menu.shownItem(0).lcField()).toEqual(' lemma');
1416 expect(menu.shownItem(1).active()).toBe(false);
1417 expect(menu.shownItem(2).active()).toBe(false);
1418
1419 menu.next();
1420 menu.next();
1421 expect(menu.shownItem(0).active()).toBe(false);
1422 expect(menu.shownItem(0).lcField()).toEqual(' lemma');
1423 expect(menu.shownItem(1).active()).toBe(false);
1424 expect(menu.shownItem(1).lcField()).toEqual(' morphology');
1425 expect(menu.shownItem(2).active()).toBe(true);
1426 expect(menu.shownItem(2).lcField()).toEqual(' part-of-speech');
1427
1428 menu.slider().movetoRel(0);
1429 expect(menu.slider().offset()).toEqual(0);
1430 expect(menu.shownItem(0).active()).toBe(false);
1431 expect(menu.shownItem(0).lcField()).toEqual(' constituency');
1432 expect(menu.shownItem(1).active()).toBe(false);
1433 expect(menu.shownItem(1).lcField()).toEqual(' lemma');
1434 expect(menu.shownItem(2).active()).toBe(false);
1435 expect(menu.shownItem(2).lcField()).toEqual(' morphology');
1436
1437 // cursor is after viewport
1438 menu.next();
1439 expect(menu.slider().offset()).toEqual(2);
1440 expect(menu.shownItem(0).active()).toBe(false);
1441 expect(menu.shownItem(0).lcField()).toEqual(' morphology');
1442 expect(menu.shownItem(1).active()).toBe(false);
1443 expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech');
1444 expect(menu.shownItem(2).active()).toBe(true);
1445 expect(menu.shownItem(2).lcField()).toEqual(' syntax');
1446
1447 menu.slider().movetoRel(0);
1448 expect(menu.slider().offset()).toEqual(0);
1449 expect(menu.shownItem(0).active()).toBe(false);
1450 expect(menu.shownItem(0).lcField()).toEqual(' constituency');
1451 expect(menu.shownItem(1).active()).toBe(false);
1452 expect(menu.shownItem(1).lcField()).toEqual(' lemma');
1453 expect(menu.shownItem(2).active()).toBe(false);
1454 expect(menu.shownItem(2).lcField()).toEqual(' morphology');
1455
1456 menu.prev();
1457 expect(menu.slider().offset()).toEqual(2);
1458 expect(menu.shownItem(0).lcField()).toEqual(' morphology');
1459 expect(menu.shownItem(0).active()).toBe(false);
1460 expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech');
1461 expect(menu.shownItem(1).active()).toBe(true);
1462 expect(menu.shownItem(2).lcField()).toEqual(' syntax');
1463 expect(menu.shownItem(2).active()).toBe(false);
1464
1465 menu.prev();
1466 menu.prev();
1467 expect(menu.slider().offset()).toEqual(1);
1468 expect(menu.shownItem(0).lcField()).toEqual(' lemma');
1469 expect(menu.shownItem(0).active()).toBe(true);
1470 expect(menu.shownItem(1).lcField()).toEqual(' morphology');
1471 expect(menu.shownItem(1).active()).toBe(false);
1472 expect(menu.shownItem(2).lcField()).toEqual(' part-of-speech');
1473 expect(menu.shownItem(2).active()).toBe(false);
1474
1475 menu.slider().movetoRel(100);
1476 expect(menu.slider().offset()).toEqual(2);
1477 expect(menu.shownItem(0).lcField()).toEqual(' morphology');
1478 expect(menu.shownItem(0).active()).toBe(false);
1479 expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech');
1480 expect(menu.shownItem(1).active()).toBe(false);
1481 expect(menu.shownItem(2).lcField()).toEqual(' syntax');
1482 expect(menu.shownItem(2).active()).toBe(false);
1483
1484 menu.prev();
1485 expect(menu.slider().offset()).toEqual(0);
1486 expect(menu.shownItem(0).lcField()).toEqual(' constituency');
1487 expect(menu.shownItem(0).active()).toBe(true);
1488 expect(menu.shownItem(1).lcField()).toEqual(' lemma');
1489 expect(menu.shownItem(1).active()).toBe(false);
1490 expect(menu.shownItem(2).lcField()).toEqual(' morphology');
1491 expect(menu.shownItem(2).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +02001492 });
1493 });
Nils Diewaldfda29d92015-01-22 17:28:01 +00001494});