blob: 5f8ab9df05919764b7973caf49cddc0c311d2c38 [file] [log] [blame]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001define(['menu'], function () {
Nils Diewaldfda29d92015-01-22 17:28:01 +00002
Akronc7448732016-04-27 14:06:58 +02003 var menuItemClass = require('menu/item');
4 var prefixClass = require('menu/prefix');
Akronc7448732016-04-27 14:06:58 +02005 var lengthFieldClass = require('menu/lengthField');
Akron1ff3ac22016-04-28 16:30:45 +02006 var menuClass = require('menu');
7
Nils Diewald7c8ced22015-04-15 19:21:00 +00008 // The OwnMenu item
9 KorAP.OwnMenuItem = {
10 create : function (params) {
11 return Object.create(menuItemClass).upgradeTo(KorAP.OwnMenuItem)._init(params);
12 },
13 content : function (content) {
14 if (arguments.length === 1) {
15 this._content = content;
16 };
17 return this._content;
18 },
19 _init : function (params) {
20 if (params[0] === undefined)
21 throw new Error("Missing parameters");
22
23 this._content = document.createTextNode(params[0]);
24 this._lcField = ' ' + this.content().textContent.toLowerCase();
25
26 return this;
27 }
28 };
29
30 // The OwnMenu
31 KorAP.OwnMenu = {
32 create : function (params) {
33 return Object.create(menuClass)
34 .upgradeTo(KorAP.OwnMenu)
Akron1ff3ac22016-04-28 16:30:45 +020035 ._init(KorAP.OwnMenuItem, undefined, undefined, params);
Nils Diewald7c8ced22015-04-15 19:21:00 +000036 }
37 };
Nils Diewaldfda29d92015-01-22 17:28:01 +000038
Nils Diewaldfda29d92015-01-22 17:28:01 +000039
Nils Diewald7c8ced22015-04-15 19:21:00 +000040 // HintMenuItem
41 KorAP.HintMenuItem = {
42 create : function (params) {
43 return Object.create(menuItemClass)
44 .upgradeTo(KorAP.HintMenuItem)
45 ._init(params);
46 },
47 content : function (content) {
48 if (arguments.length === 1) {
49 this._content = content;
50 };
51 return this._content;
52 },
53 _init : function (params) {
54 if (params[0] === undefined || params[1] === undefined)
55 throw new Error("Missing parameters");
56
57 this._name = params[0];
58 this._action = params[1];
59 this._lcField = ' ' + this._name.toLowerCase();
60
61 if (params.length > 2) {
62 this._desc = params[2];
63 this._lcField += " " + this._desc.toLowerCase();
64 };
65
66 return this;
67 },
68
69 name : function () {
70 return this._name;
71 },
72 action : function () {
73 return this._action;
74 },
75 desc : function () {
76 return this._desc;
77 },
78 element : function () {
79 // already defined
80 if (this._element !== undefined)
81 return this._element;
82
83 // Create list item
84 var li = document.createElement("li");
85 li.setAttribute("data-action", this._action);
86
87 // Create title
88 var name = document.createElement("strong");
89 name.appendChild(document.createTextNode(this._name));
90
91 li.appendChild(name);
92
93 // Create description
94 if (this._desc !== undefined) {
95 var desc = document.createElement("span");
96 desc.appendChild(document.createTextNode(this._desc));
97 li.appendChild(desc);
98 };
99 return this._element = li;
100 }
101 };
Nils Diewald86dad5b2015-01-28 15:09:07 +0000102
103
Nils Diewald7c8ced22015-04-15 19:21:00 +0000104 // HintMenu
105 KorAP.HintMenu = {
106 create : function (context, params) {
107 var obj = Object.create(menuClass)
108 .upgradeTo(KorAP.HintMenu)
Akron1ff3ac22016-04-28 16:30:45 +0200109 ._init(KorAP.HintMenuItem, undefined, undefined, params);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000110 obj._context = context;
111 return obj;
112 }
113 };
Nils Diewald86dad5b2015-01-28 15:09:07 +0000114
115
Nils Diewald7c8ced22015-04-15 19:21:00 +0000116 // The ComplexMenuItem
117 KorAP.ComplexMenuItem = {
118 create : function (params) {
119 return Object.create(menuItemClass)
120 .upgradeTo(KorAP.ComplexMenuItem)
121 ._init(params);
122 },
123 content : function (content) {
124 if (arguments.length === 1) {
125 this._content = content;
126 };
127 return this._content;
128 },
129 _init : function (params) {
130 if (params[0] === undefined)
131 throw new Error("Missing parameters");
132
133 var r = document.createElement('div');
134 for (var i = 1; i <= params.length; i++) {
135 var h = document.createElement('h' + i);
136 h.appendChild(document.createTextNode(params[i-1]));
137 r.appendChild(h);
138 };
139
140 this._content = r;
141 this._lcField = ' ' + this.content().textContent.toLowerCase();
142
143 return this;
144 }
145 };
Nils Diewald2fe12e12015-03-06 16:47:06 +0000146
147
Nils Diewald7c8ced22015-04-15 19:21:00 +0000148 describe('KorAP.MenuItem', function () {
149 it('should be initializable', function () {
150 expect(
151 function() { menuItemClass.create([]) }
152 ).toThrow(new Error("Missing parameters"));
Nils Diewald2fe12e12015-03-06 16:47:06 +0000153
Nils Diewald7c8ced22015-04-15 19:21:00 +0000154 expect(
155 function() { KorAP.OwnMenuItem.create([]) }
156 ).toThrow(new Error("Missing parameters"));
Nils Diewald2fe12e12015-03-06 16:47:06 +0000157
Nils Diewald7c8ced22015-04-15 19:21:00 +0000158 var mi = KorAP.OwnMenuItem.create(["Baum"]);
159 expect(mi.element().firstChild.nodeValue).toEqual('Baum');
160 expect(mi.lcField()).toEqual(' baum');
161 });
Nils Diewald2fe12e12015-03-06 16:47:06 +0000162
Nils Diewald7c8ced22015-04-15 19:21:00 +0000163 it('shouldn\'t have a reference to the menu', function () {
164 var menuItem = KorAP.OwnMenuItem.create(['Test']);
165 expect(menuItem.menu()).toBe(undefined);
166 });
167
168 it('should be activatable and deactivateable by class', function () {
169 var menuItem = KorAP.OwnMenuItem.create(['Test']);
170
171 expect(menuItem.active()).toBe(false);
172 expect(menuItem.element().getAttribute("class")).toBe(null);
173 menuItem.active(true);
174 expect(menuItem.active()).toBe(true);
175 expect(menuItem.element().getAttribute("class")).toEqual("active");
176 menuItem.active(false); // Is active
177 expect(menuItem.active()).toBe(false);
178 expect(menuItem.element().getAttribute("class")).toEqual("");
179 menuItem.active(true);
180 expect(menuItem.active()).toBe(true);
181 expect(menuItem.element().getAttribute("class")).toEqual("active");
182
183 menuItem = KorAP.OwnMenuItem.create(['Spiegel']);
184 expect(menuItem.active()).toBe(false);
185 expect(menuItem.element().getAttribute("class")).toBe(null);
186 menuItem.active(false); // Is not active
187 expect(menuItem.active()).toBe(false);
188 expect(menuItem.element().getAttribute("class")).toBe(null);
189 });
190
191 it('should be set to boundary', function () {
192 var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']);
193 expect(menuItem.active()).toBe(false);
194 expect(menuItem.element().getAttribute("class")).toBe(null);
195
196 // Set active
197 menuItem.active(true);
198 expect(menuItem.active()).toBe(true);
199 expect(menuItem.noMore()).toBe(false);
200 expect(menuItem.element().getAttribute("class")).toEqual("active");
201
202 // Set no more
203 menuItem.noMore(true);
204 expect(menuItem.active()).toBe(true);
205 expect(menuItem.noMore()).toBe(true);
206 expect(menuItem.element().getAttribute("class")).toEqual("active no-more");
207
208 // No no more
209 menuItem.noMore(false);
210 expect(menuItem.active()).toBe(true);
211 expect(menuItem.noMore()).toBe(false);
212 expect(menuItem.element().getAttribute("class")).toEqual("active");
213
214 // Set no more, deactivate
215 menuItem.noMore(true);
216 menuItem.active(false);
217 expect(menuItem.active()).toBe(false);
218 expect(menuItem.noMore()).toBe(true);
219 expect(menuItem.element().getAttribute("class")).toEqual("no-more");
220
221 // Set active
222 menuItem.active(true);
223 expect(menuItem.active()).toBe(true);
224 expect(menuItem.noMore()).toBe(true);
225 expect(menuItem.element().getAttribute("class")).toEqual("no-more active");
226 });
Nils Diewald2fe12e12015-03-06 16:47:06 +0000227
228
Nils Diewald7c8ced22015-04-15 19:21:00 +0000229 it('should be highlightable', function () {
230 // Highlight in the middle
231 var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']);
232 menuItem.highlight("ren");
233 expect(menuItem.element().innerHTML).toEqual("Co<mark>reN</mark>LP");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000234
Nils Diewald7c8ced22015-04-15 19:21:00 +0000235 menuItem.lowlight();
236 expect(menuItem.element().innerHTML).toEqual("CoreNLP");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000237
Nils Diewald7c8ced22015-04-15 19:21:00 +0000238 var plain = "<div><h1>CoreNLP</h1><h2>corenlp/</h2></div>";
Nils Diewaldfda29d92015-01-22 17:28:01 +0000239
Nils Diewald7c8ced22015-04-15 19:21:00 +0000240 // Starting highlight
241 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
242 menuItem.highlight("cor");
243 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 +0000244
Nils Diewald7c8ced22015-04-15 19:21:00 +0000245 menuItem.lowlight();
246 expect(menuItem.element().innerHTML).toEqual(plain);
Nils Diewald6e43ffd2015-03-25 18:55:39 +0000247
Nils Diewald7c8ced22015-04-15 19:21:00 +0000248 // Starting highlight - short
249 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
250 menuItem.highlight("c");
251 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 +0000252
Nils Diewald7c8ced22015-04-15 19:21:00 +0000253 menuItem.lowlight();
254 expect(menuItem.element().innerHTML).toEqual(plain);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000255
Nils Diewald7c8ced22015-04-15 19:21:00 +0000256 // Highlight at the end
257 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
258 menuItem.highlight("nlp");
259 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 +0000260
Nils Diewald7c8ced22015-04-15 19:21:00 +0000261 menuItem.lowlight();
262 expect(menuItem.element().innerHTML).toEqual(plain);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000263
Nils Diewald7c8ced22015-04-15 19:21:00 +0000264 // Highlight at the end - short
265 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
266 menuItem.highlight("p");
267 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 +0000268
Nils Diewald7c8ced22015-04-15 19:21:00 +0000269 menuItem.lowlight();
270 expect(menuItem.element().innerHTML).toEqual(plain);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000271
Nils Diewald7c8ced22015-04-15 19:21:00 +0000272 // No highlight
273 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
274 menuItem.highlight("xp");
275 expect(menuItem.element().innerHTML).toEqual(plain);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000276
Nils Diewald7c8ced22015-04-15 19:21:00 +0000277 menuItem.lowlight();
278 expect(menuItem.element().innerHTML).toEqual(plain);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000279
Nils Diewald7c8ced22015-04-15 19:21:00 +0000280 // Highlight in the middle - first
281 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
282 menuItem.highlight("ren");
283 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>");
284
285 plain = "<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Example</h3></div>"
286
287 menuItem.lowlight();
288 expect(menuItem.element().innerHTML).toEqual(plain);
289
290 // Highlight in the middle - second
291 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
292 menuItem.highlight("ampl");
293 expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Ex<mark>ampl</mark>e</h3></div>");
294
295 menuItem.lowlight();
296 expect(menuItem.element().innerHTML).toEqual(plain);
297
298 // Highlight in the middle - both
299 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
300 menuItem.highlight("e");
301 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>");
302
303 menuItem.lowlight();
304 expect(menuItem.element().innerHTML).toEqual(plain);
305
306 // Highlight in the end - second
307 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
308 menuItem.highlight("le");
309 expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Examp<mark>le</mark></h3></div>");
310
311 menuItem.lowlight();
312 expect(menuItem.element().innerHTML).toEqual(plain);
313
314 // Highlight at the beginning - second
315 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
316 menuItem.highlight("this");
317 expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3><mark>This</mark> is my Example</h3></div>");
318
319 menuItem.lowlight();
320 expect(menuItem.element().innerHTML).toEqual(plain);
321 });
Nils Diewaldfda29d92015-01-22 17:28:01 +0000322 });
323
324
Nils Diewald7c8ced22015-04-15 19:21:00 +0000325 describe('KorAP.Menu', function () {
Nils Diewald86dad5b2015-01-28 15:09:07 +0000326 var list = [
Nils Diewald7c8ced22015-04-15 19:21:00 +0000327 ["Constituency", "c=", "Example 1"],
328 ["Lemma", "l="],
329 ["Morphology", "m=", "Example 2"],
330 ["Part-of-Speech", "p="],
331 ["Syntax", "syn="]
Nils Diewald86dad5b2015-01-28 15:09:07 +0000332 ];
Nils Diewaldfda29d92015-01-22 17:28:01 +0000333
Nils Diewald7c8ced22015-04-15 19:21:00 +0000334 var demolist = [
335 ['Titel', 'title'],
336 ['Untertitel', 'subTitle'],
337 ['Veröffentlichungsdatum', 'pubDate'],
338 ['Länge', 'length'],
339 ['Autor', 'author']
340 ];
Nils Diewaldfda29d92015-01-22 17:28:01 +0000341
Nils Diewald7c8ced22015-04-15 19:21:00 +0000342 var demolonglist = [
343 ['Titel', 'title'],
344 ['Untertitel', 'subTitle'],
345 ['Veröffentlichungsdatum', 'pubDate'],
346 ['Länge', 'length'],
347 ['Autor', 'author'],
348 ['Genre', 'genre'],
349 ['corpusID', 'corpusID'],
350 ['docID', 'docID'],
351 ['textID', 'textID'],
352 ];
Nils Diewald86dad5b2015-01-28 15:09:07 +0000353
Nils Diewald7c8ced22015-04-15 19:21:00 +0000354 it('should be initializable', function () {
355 var list = [
356 ["Constituency"],
357 ["Lemma"],
358 ["Morphology"],
359 ["Part-of-Speech"],
360 ["Syntax"]
361 ];
Nils Diewaldfda29d92015-01-22 17:28:01 +0000362
Nils Diewald7c8ced22015-04-15 19:21:00 +0000363 var menu = KorAP.OwnMenu.create(list);
Akronc1457bf2015-06-11 19:24:00 +0200364 menu._firstActive = true;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000365 expect(menu.itemClass()).toEqual(KorAP.OwnMenuItem);
366 expect(menu.element().nodeName).toEqual('UL');
367 expect(menu.element().style.opacity).toEqual("0");
368 expect(menu.limit()).toEqual(8);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000369
Nils Diewald7c8ced22015-04-15 19:21:00 +0000370 menu.limit(9);
371 expect(menu.limit()).toEqual(9);
Nils Diewald86dad5b2015-01-28 15:09:07 +0000372
Nils Diewald7c8ced22015-04-15 19:21:00 +0000373 menu.limit(8);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000374
Nils Diewald7c8ced22015-04-15 19:21:00 +0000375 // view
376 menu.show();
377
378 // First element in list
379 expect(menu.item(0).active()).toBe(true);
380 expect(menu.item(0).noMore()).toBe(true);
381
382 // Middle element in list
383 expect(menu.item(2).active()).toBe(false);
384 expect(menu.item(2).noMore()).toBe(false);
385
386 // Last element in list
387 expect(menu.item(menu.length() - 1).active()).toBe(false);
388 expect(menu.item(menu.length() - 1).noMore()).toBe(true);
389 });
390
391 it('should have a reference to the menu', function () {
392 var menu = KorAP.HintMenu.create("cnx/", list);
393 expect(menu.item(0).menu()).toEqual(menu);
394
395 menu = KorAP.HintMenu.create("cnx/", list);
396 expect(menu.element().menu).toEqual(menu);
397 });
398
399
400 it('should be visible', function () {
401 var menu = KorAP.HintMenu.create("cnx/", list);
402 expect(menu.delete()).toBe(undefined);
403 menu.limit(3);
404
405 expect(menu.show()).toBe(true);
406
Akronf86eaea2016-05-13 18:02:27 +0200407 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
408 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>");
409 expect(menu.element().childNodes[4].getAttribute("data-action")).toEqual("l=");
410 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
411 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000412
413 // Check boundaries
Akronf86eaea2016-05-13 18:02:27 +0200414 expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(true);
Akronc7448732016-04-27 14:06:58 +0200415 expect(menu.element().childNodes[4].classList.contains("no-more")).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200416 expect(menu.element().childNodes[5].classList.contains("no-more")).toBe(false);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000417 });
418
419 it('should be filterable', function () {
420 var menu = KorAP.HintMenu.create("cnx/", list);
421 menu.limit(3);
422 expect(menu.prefix("o").show()).toBe(true);
423 expect(menu.element().childNodes[0].innerHTML).toEqual("o");
Akronf86eaea2016-05-13 18:02:27 +0200424 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
425 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>");
426 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
427 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000428
429 // Check boundaries
Akronf86eaea2016-05-13 18:02:27 +0200430 expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(true);
431 expect(menu.element().childNodes[4].classList.contains("no-more")).toBe(false);
432 expect(menu.element().childNodes[5].classList.contains("no-more")).toBe(true);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000433
434 menu.limit(2);
435
436 expect(menu.prefix("o").show()).toBe(true);
437 expect(menu.element().childNodes[0].innerHTML).toEqual("o");
Akronf86eaea2016-05-13 18:02:27 +0200438 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
439 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>");
440 expect(menu.element().childNodes[5]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000441
442 // Check boundaries
Akronf86eaea2016-05-13 18:02:27 +0200443 expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(true);
444 expect(menu.element().childNodes[4].classList.contains("no-more")).toBe(false);
445 expect(menu.element().childNodes[5]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000446
447 expect(menu.prefix("e").show()).toBe(true);
448 expect(menu.element().childNodes[0].innerHTML).toEqual("e");
Akronf86eaea2016-05-13 18:02:27 +0200449 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
450 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
451 expect(menu.element().childNodes[5]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000452
453 menu.limit(5);
454 expect(menu.prefix("a").show()).toBe(true);
455 expect(menu.element().childNodes[0].innerHTML).toEqual("a");
Akronf86eaea2016-05-13 18:02:27 +0200456 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Ex<mark>a</mark>mple 1</span>");
457 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemm<mark>a</mark></strong>");
458 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Ex<mark>a</mark>mple 2</span>");
459 expect(menu.element().childNodes[6].innerHTML).toEqual("<strong>P<mark>a</mark>rt-of-Speech</strong>");
460 expect(menu.element().childNodes[7].innerHTML).toEqual("<strong>Synt<mark>a</mark>x</strong>");
461 expect(menu.element().childNodes[8]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000462 });
463
464
465 it('should be nextable', function () {
466 var menu = KorAP.HintMenu.create("cnx/", list);
Akronc1457bf2015-06-11 19:24:00 +0200467 menu._firstActive = true;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000468
469 // Show only 3 items
470 menu.limit(3);
471 expect(menu.show()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +0200472 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000473 expect(menu.shownItem(0).active()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +0200474 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000475 expect(menu.shownItem(1).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200476 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000477 expect(menu.shownItem(2).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200478 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000479
480 // Activate next (1)
481 menu.next();
Akronf86eaea2016-05-13 18:02:27 +0200482 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000483 expect(menu.shownItem(0).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200484 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000485 expect(menu.shownItem(1).active()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +0200486 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000487 expect(menu.shownItem(2).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200488 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000489
490 // Activate next (2)
491 menu.next();
Akronf86eaea2016-05-13 18:02:27 +0200492 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000493 expect(menu.shownItem(0).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200494 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000495 expect(menu.shownItem(1).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200496 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000497 expect(menu.shownItem(2).active()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +0200498 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000499
500 // Activate next (3)
501 // scroll!
502 menu.next();
Akronf86eaea2016-05-13 18:02:27 +0200503 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000504 expect(menu.shownItem(0).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200505 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000506 expect(menu.shownItem(1).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200507 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000508 expect(menu.shownItem(2).active()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +0200509 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000510
511 // Activate next (4)
512 menu.next();
Akronf86eaea2016-05-13 18:02:27 +0200513 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000514 expect(menu.shownItem(0).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200515 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000516 expect(menu.shownItem(1).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200517 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Syntax</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000518 expect(menu.shownItem(2).active()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +0200519 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000520
521 // Activate next (5) - ROLL
522 menu.next();
Akronf86eaea2016-05-13 18:02:27 +0200523 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000524 expect(menu.shownItem(0).active()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +0200525 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000526 expect(menu.shownItem(1).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200527 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000528 expect(menu.shownItem(2).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200529 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000530
531 // Active next (6)
532 menu.next();
Akronf86eaea2016-05-13 18:02:27 +0200533 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000534 expect(menu.shownItem(0).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200535 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000536 expect(menu.shownItem(1).active()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +0200537 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000538 expect(menu.shownItem(2).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200539 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000540 });
541
542 it('should be prevable', function () {
543 var menu = KorAP.HintMenu.create("cnx/", list);
Akronc1457bf2015-06-11 19:24:00 +0200544 menu._firstActive = true;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000545 menu.limit(3);
546 expect(menu.show()).toBe(true);
547
Akronf86eaea2016-05-13 18:02:27 +0200548 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000549 expect(menu.shownItem(0).active()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +0200550 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000551 expect(menu.shownItem(1).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200552 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000553 expect(menu.shownItem(2).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200554 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000555
556 // Activate prev (1) - roll to bottom
557 menu.prev();
Akronf86eaea2016-05-13 18:02:27 +0200558 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000559 expect(menu.shownItem(0).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200560 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000561 expect(menu.shownItem(1).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200562 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Syntax</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000563 expect(menu.shownItem(2).active()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +0200564 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000565
566 // Activate prev (2)
567 menu.prev();
Akronf86eaea2016-05-13 18:02:27 +0200568 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000569 expect(menu.shownItem(0).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200570 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000571 expect(menu.shownItem(1).active()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +0200572 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Syntax</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000573 expect(menu.shownItem(2).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200574 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000575
576 // Activate prev (3)
577 menu.prev();
578 expect(menu.shownItem(0).name()).toEqual("Morphology");
579 expect(menu.shownItem(0).active()).toBe(true);
580 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
581 expect(menu.shownItem(1).active()).toBe(false);
582 expect(menu.shownItem(2).name()).toEqual("Syntax");
583 expect(menu.shownItem(2).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200584 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000585
586 // Activate prev (4)
587 menu.prev();
588 expect(menu.shownItem(0).name()).toEqual("Lemma");
589 expect(menu.shownItem(0).active()).toBe(true);
590 expect(menu.shownItem(1).name()).toEqual("Morphology");
591 expect(menu.shownItem(1).active()).toBe(false);
592 expect(menu.shownItem(2).name()).toEqual("Part-of-Speech");
593 expect(menu.shownItem(2).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200594 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000595
596 // Activate prev (5)
597 menu.prev();
598 expect(menu.shownItem(0).name()).toEqual("Constituency");
599 expect(menu.shownItem(0).active()).toBe(true);
600 expect(menu.shownItem(1).name()).toEqual("Lemma");
601 expect(menu.shownItem(1).active()).toBe(false);
602 expect(menu.shownItem(2).name()).toEqual("Morphology");
603 expect(menu.shownItem(2).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200604 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000605
606 // Activate next (1)
607 menu.next();
608 expect(menu.shownItem(0).name()).toEqual("Constituency");
609 expect(menu.shownItem(0).active()).toBe(false);
610 expect(menu.shownItem(1).name()).toEqual("Lemma");
611 expect(menu.shownItem(1).active()).toBe(true);
612 expect(menu.shownItem(2).name()).toEqual("Morphology");
613 expect(menu.shownItem(2).active()).toBe(false);
Akronf86eaea2016-05-13 18:02:27 +0200614 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000615
616 // Activate prev (6)
617 menu.prev();
618
619 // Activate prev (7)
620 menu.prev();
621 expect(menu.shownItem(0).name()).toEqual("Morphology");
622 expect(menu.shownItem(0).active()).toBe(false);
623 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
624 expect(menu.shownItem(1).active()).toBe(false);
625 expect(menu.shownItem(2).name()).toEqual("Syntax");
626 expect(menu.shownItem(2).active()).toBe(true);
Akronf86eaea2016-05-13 18:02:27 +0200627 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000628 });
629
630
631 it('should be navigatable and filterable (prefix = "o")', function () {
632 var menu = KorAP.HintMenu.create("cnx/", list);
Akronc1457bf2015-06-11 19:24:00 +0200633 menu._firstActive = true;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000634 menu.limit(2);
635
636 expect(menu.prefix("o").show()).toBe(true);
637 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200638 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 +0000639 expect(menu.shownItem(0).active()).toBe(true);
640 expect(menu.shownItem(1).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200641 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 +0000642 expect(menu.shownItem(1).active()).toBe(false);
643 expect(menu.shownItem(2)).toBe(undefined);
644
645 // Next (1)
646 menu.next();
647 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200648 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 +0000649 expect(menu.shownItem(0).active()).toBe(false);
650 expect(menu.shownItem(1).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200651 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 +0000652 expect(menu.shownItem(1).active()).toBe(true);
653 expect(menu.shownItem(2)).toBe(undefined);
654
655 // Next (2)
656 menu.next();
657 expect(menu.shownItem(0).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200658 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 +0000659 expect(menu.shownItem(0).active()).toBe(false);
660 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
Akronf86eaea2016-05-13 18:02:27 +0200661 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000662 expect(menu.shownItem(1).active()).toBe(true);
663 expect(menu.shownItem(2)).toBe(undefined);
664
665 // Next (3) - to prefix
666 menu.next();
667 expect(menu.shownItem(0).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200668 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 +0000669 expect(menu.shownItem(0).active()).toBe(false);
670 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
Akronf86eaea2016-05-13 18:02:27 +0200671 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000672 expect(menu.shownItem(1).active()).toBe(false);
673 expect(menu.shownItem(2)).toBe(undefined);
674
675 menu.next();
676 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200677 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 +0000678 expect(menu.shownItem(0).active()).toBe(true);
679 expect(menu.shownItem(1).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200680 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 +0000681 expect(menu.shownItem(1).active()).toBe(false);
682 expect(menu.shownItem(2)).toBe(undefined);
683 });
684
685
686 it('should be navigatable and filterable (prefix = "ex", "e")', function () {
687 var menu = KorAP.HintMenu.create("cnx/", list);
Akronc1457bf2015-06-11 19:24:00 +0200688 menu._firstActive = true;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000689
690 menu.limit(2);
691 expect(menu.prefix("ex").show()).toBe(true);
692
693 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200694 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000695 expect(menu.shownItem(0).active()).toBe(true);
696 expect(menu.shownItem(1).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200697 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000698 expect(menu.shownItem(1).active()).toBe(false);
699 expect(menu.shownItem(2)).toBe(undefined);
700
701 // Next (1)
702 menu.next();
703 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200704 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000705 expect(menu.shownItem(0).active()).toBe(false);
706 expect(menu.shownItem(1).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200707 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000708 expect(menu.shownItem(1).active()).toBe(true);
709 expect(menu.shownItem(2)).toBe(undefined);
710
711 // Next (2)
712 menu.next();
713
714 expect(menu.prefix()).toEqual('ex');
715 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200716 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000717 expect(menu.shownItem(0).active()).toBe(false);
718
719 expect(menu.shownItem(1).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200720 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000721 expect(menu.shownItem(1).active()).toBe(false);
722 expect(menu.shownItem(2)).toBe(undefined);
723
724 // Reset limit
725 menu.limit(5);
726
727 // Change show
728 expect(menu.prefix("e").show()).toBe(true);
729 expect(menu._prefix.active()).toBe(false);
730 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200731 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 +0000732 expect(menu.shownItem(0).active()).toBe(true);
733 expect(menu.shownItem(1).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200734 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 +0000735 expect(menu.shownItem(1).active()).toBe(false);
736 expect(menu.shownItem(2)).toBe(undefined);
737
738 // Next (1)
739 menu.next();
740 expect(menu._prefix.active()).toBe(false);
741 expect(menu.prefix()).toEqual('e');
742 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200743 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 +0000744 expect(menu.shownItem(0).active()).toBe(false);
745 expect(menu.shownItem(1).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200746 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 +0000747 expect(menu.shownItem(1).active()).toBe(true);
748 expect(menu.shownItem(2)).toBe(undefined);
749
750 // Next (2)
751 menu.next();
752 expect(menu._prefix.active()).toBe(true);
753 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200754 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 +0000755 expect(menu.shownItem(0).active()).toBe(false);
756 expect(menu.shownItem(1).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200757 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 +0000758 expect(menu.shownItem(1).active()).toBe(false);
759 expect(menu.shownItem(2)).toBe(undefined);
760
761 // Next (3)
762 menu.next();
763 expect(menu._prefix.active()).toBe(false);
764 expect(menu.shownItem(0).name()).toEqual("Constituency");
Akronf86eaea2016-05-13 18:02:27 +0200765 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 +0000766 expect(menu.shownItem(0).active()).toBe(true);
767 expect(menu.shownItem(1).name()).toEqual("Morphology");
Akronf86eaea2016-05-13 18:02:27 +0200768 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 +0000769 expect(menu.shownItem(1).active()).toBe(false);
770 expect(menu.shownItem(2)).toBe(undefined);
771 });
772
773
774 it('shouldn\'t be viewable with failing prefix', function () {
775 var menu = KorAP.HintMenu.create("cnx/", list);
776 menu.limit(2);
777 expect(menu.prefix("exit").show()).toBe(false);
778 });
779
Akron37513a62015-11-17 01:07:11 +0100780
Nils Diewald7c8ced22015-04-15 19:21:00 +0000781 it('should be navigatable with prefix', function () {
782 var menu = KorAP.HintMenu.create("cnx/", demolist);
Akronc1457bf2015-06-11 19:24:00 +0200783 menu._firstActive = true;
784
Nils Diewald7c8ced22015-04-15 19:21:00 +0000785 menu.limit(3);
786
787 expect(menu.show()).toBe(true);
788 expect(menu.prefix()).toEqual("");
789
790 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200791 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000792 expect(menu.shownItem(0).active()).toBe(true);
793 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200794 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000795 expect(menu.shownItem(1).active()).toBe(false);
796 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200797 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000798 expect(menu.shownItem(2).active()).toBe(false);
799 expect(menu.shownItem(3)).toBe(undefined);
800
801 menu._prefix.add('a');
802 expect(menu.show()).toBe(true);
803 expect(menu.prefix()).toEqual("a");
804 expect(menu.shownItem(0).name()).toEqual("Autor");
Akronf86eaea2016-05-13 18:02:27 +0200805 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000806
807 menu._prefix.add('u');
808 expect(menu.show()).toBe(true);
809 expect(menu.prefix()).toEqual("au");
810 expect(menu.shownItem(0).name()).toEqual("Autor");
Akronf86eaea2016-05-13 18:02:27 +0200811 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong><mark>Au</mark>tor</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000812
Nils Diewald7148c6f2015-05-04 15:07:53 +0000813 menu._prefix.chop();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000814 expect(menu.show()).toBe(true);
815 expect(menu.prefix()).toEqual("a");
816 expect(menu.shownItem(0).name()).toEqual("Autor");
Akronf86eaea2016-05-13 18:02:27 +0200817 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000818
Nils Diewald7148c6f2015-05-04 15:07:53 +0000819 menu._prefix.chop();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000820 expect(menu.show()).toBe(true);
821 expect(menu.prefix()).toEqual("");
822 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200823 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000824 expect(menu.shownItem(0).active()).toBe(true);
825 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200826 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000827 expect(menu.shownItem(1).active()).toBe(false);
828 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200829 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000830 expect(menu.shownItem(2).active()).toBe(false);
831 expect(menu.shownItem(3)).toBe(undefined);
832
833 // Forward
Nils Diewald7148c6f2015-05-04 15:07:53 +0000834 menu._prefix.chop();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000835 expect(menu.show()).toBe(true);
836 expect(menu.prefix()).toEqual("");
837 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200838 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000839 expect(menu.shownItem(0).active()).toBe(true);
840 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200841 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000842 expect(menu.shownItem(1).active()).toBe(false);
843 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200844 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000845 expect(menu.shownItem(2).active()).toBe(false);
846
847 // Forward
848 menu.next();
849 expect(menu.prefix()).toEqual("");
850 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200851 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000852 expect(menu.shownItem(0).active()).toBe(false);
853 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200854 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000855 expect(menu.shownItem(1).active()).toBe(true);
856 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200857 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000858 expect(menu.shownItem(2).active()).toBe(false);
859 expect(menu.shownItem(3)).toBe(undefined);
860
861 // Forward
862 menu.next();
863 expect(menu.prefix()).toEqual("");
864 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200865 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000866 expect(menu.shownItem(0).active()).toBe(false);
867 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200868 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000869 expect(menu.shownItem(1).active()).toBe(false);
870 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200871 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000872 expect(menu.shownItem(2).active()).toBe(true);
873 expect(menu.shownItem(3)).toBe(undefined);
874
875 // Forward
876 menu.next();
877 expect(menu.prefix()).toEqual("");
878 expect(menu.shownItem(0).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200879 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Untertitel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000880 expect(menu.shownItem(0).active()).toBe(false);
881 expect(menu.shownItem(1).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200882 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000883 expect(menu.shownItem(1).active()).toBe(false);
884 expect(menu.shownItem(2).name()).toEqual("Länge");
Akronf86eaea2016-05-13 18:02:27 +0200885 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Länge</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000886 expect(menu.shownItem(2).active()).toBe(true);
887 expect(menu.shownItem(3)).toBe(undefined);
888
889 // Forward
890 menu.next();
891 expect(menu.prefix()).toEqual("");
892 expect(menu.shownItem(0).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200893 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000894 expect(menu.shownItem(0).active()).toBe(false);
895 expect(menu.shownItem(1).name()).toEqual("Länge");
Akronf86eaea2016-05-13 18:02:27 +0200896 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Länge</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000897 expect(menu.shownItem(1).active()).toBe(false);
898 expect(menu.shownItem(2).name()).toEqual("Autor");
Akronf86eaea2016-05-13 18:02:27 +0200899 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Autor</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000900 expect(menu.shownItem(2).active()).toBe(true);
901 expect(menu.shownItem(3)).toBe(undefined);
902
903 // Forward
904 menu.next();
905 expect(menu.prefix()).toEqual("");
906 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200907 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Titel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000908 expect(menu.shownItem(0).active()).toBe(true);
909 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200910 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertitel</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000911 expect(menu.shownItem(1).active()).toBe(false);
912 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Akronf86eaea2016-05-13 18:02:27 +0200913 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000914 expect(menu.shownItem(2).active()).toBe(false);
915 });
916
917
918 it('should be navigatable with a prefix (1)', function () {
919 var menu = KorAP.HintMenu.create("cnx/", demolist);
Akronc1457bf2015-06-11 19:24:00 +0200920 menu._firstActive = true;
921
Nils Diewald7c8ced22015-04-15 19:21:00 +0000922 menu.limit(3);
923
924 expect(menu.show()).toBe(true);
925 expect(menu.prefix()).toEqual("");
926
927 menu.prefix('el');
928 expect(menu.show()).toBe(true);
929
930 expect(menu.prefix()).toEqual("el");
931 expect(menu._prefix.active()).toEqual(false);
932 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200933 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000934 expect(menu.shownItem(0).active()).toBe(true);
935 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200936 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000937 expect(menu.shownItem(1).active()).toBe(false);
938 expect(menu.shownItem(2)).toBe(undefined);
939
940 // Forward
941 menu.next();
942 expect(menu.prefix()).toEqual("el");
943 expect(menu._prefix.active()).toEqual(false);
944 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200945 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000946 expect(menu.shownItem(0).active()).toBe(false);
947 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200948 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000949 expect(menu.shownItem(1).active()).toBe(true);
950 expect(menu.shownItem(2)).toBe(undefined);
951
952 // Forward
953 menu.next();
954 expect(menu.prefix()).toEqual("el");
955 expect(menu._prefix.active()).toEqual(true);
956 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200957 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000958 expect(menu.shownItem(0).active()).toBe(false);
959 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200960 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000961 expect(menu.shownItem(1).active()).toBe(false);
962 expect(menu.shownItem(2)).toBe(undefined);
963
964 // Backward
965 menu.prev();
966 expect(menu.prefix()).toEqual("el");
967 expect(menu._prefix.active()).toEqual(false);
968 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200969 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000970 expect(menu.shownItem(0).active()).toBe(false);
971
972 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200973 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000974 expect(menu.shownItem(1).active()).toBe(true);
975 expect(menu.shownItem(2)).toBe(undefined);
976 });
977
978
979 it('should be navigatable with a prefix (2)', function () {
980 var menu = KorAP.HintMenu.create("cnx/", demolist);
Akronc1457bf2015-06-11 19:24:00 +0200981 menu._firstActive = true;
982
Nils Diewald7c8ced22015-04-15 19:21:00 +0000983 menu.limit(3);
984 expect(menu.show()).toBe(true);
985 expect(menu.prefix()).toEqual("");
986 menu.prefix('el');
987 expect(menu.show()).toBe(true);
988
989 expect(menu.prefix()).toEqual("el");
990 expect(menu._prefix.active()).toEqual(false);
991 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +0200992 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000993 expect(menu.shownItem(0).active()).toBe(true);
994 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +0200995 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000996 expect(menu.shownItem(1).active()).toBe(false);
997 expect(menu.shownItem(2)).toBe(undefined);
998
999 // Backward
1000 menu.prev();
1001 expect(menu._prefix.active()).toEqual(true);
1002
1003 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +02001004 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001005 expect(menu.shownItem(0).active()).toBe(false);
1006
1007 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +02001008 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001009 expect(menu.shownItem(1).active()).toBe(false);
1010 expect(menu.shownItem(2)).toBe(undefined);
1011
1012 // Backward
1013 menu.prev();
1014 expect(menu._prefix.active()).toEqual(false);
1015 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +02001016 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001017 expect(menu.shownItem(0).active()).toBe(false);
1018 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +02001019 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001020 expect(menu.shownItem(1).active()).toBe(true);
1021 expect(menu.shownItem(2)).toBe(undefined);
1022 });
1023
1024 it('should be navigatable with a prefix (3)', function () {
1025 var menu = KorAP.HintMenu.create("cnx/", demolist);
Akronc1457bf2015-06-11 19:24:00 +02001026 menu._firstActive = true;
Nils Diewald7c8ced22015-04-15 19:21:00 +00001027 menu.limit(3);
1028 expect(menu.show()).toBe(true);
1029 expect(menu.prefix()).toEqual("");
1030 menu.prefix('el');
1031 expect(menu.show()).toBe(true);
1032
1033 expect(menu.prefix()).toEqual("el");
1034 expect(menu._prefix.active()).toEqual(false);
1035 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +02001036 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001037 expect(menu.shownItem(0).active()).toBe(true);
1038 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +02001039 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001040 expect(menu.shownItem(1).active()).toBe(false);
1041 expect(menu.shownItem(2)).toBe(undefined);
1042
1043 // Backward
1044 menu.prev();
1045 expect(menu._prefix.active()).toEqual(true);
1046 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +02001047 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001048 expect(menu.shownItem(0).active()).toBe(false);
1049 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +02001050 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001051 expect(menu.shownItem(1).active()).toBe(false);
1052 expect(menu.shownItem(2)).toBe(undefined);
1053
1054
1055 // Forward
1056 menu.next();
1057 expect(menu.prefix()).toEqual("el");
1058 expect(menu._prefix.active()).toEqual(false);
1059 expect(menu.shownItem(0).name()).toEqual("Titel");
Akronf86eaea2016-05-13 18:02:27 +02001060 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001061 expect(menu.shownItem(0).active()).toBe(true);
1062 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Akronf86eaea2016-05-13 18:02:27 +02001063 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Nils Diewald7c8ced22015-04-15 19:21:00 +00001064 expect(menu.shownItem(1).active()).toBe(false);
1065 expect(menu.shownItem(2)).toBe(undefined);
1066
1067 });
1068
1069 xit('should be page downable');
1070 xit('should be page upable');
1071
Akron37513a62015-11-17 01:07:11 +01001072 it('should scroll to a chosen value', function () {
1073 var menu = KorAP.OwnMenu.create(demolist);
1074 menu.limit(3);
1075 this._active = 5;
1076 });
1077
Nils Diewald7148c6f2015-05-04 15:07:53 +00001078 xit('should highlight a chosen value');
1079 });
1080
1081 describe('KorAP.Prefix', function () {
1082 it('should be initializable', function () {
1083 var p = prefixClass.create();
1084 expect(p.element().classList.contains('pref')).toBeTruthy();
1085 expect(p.isSet()).not.toBeTruthy();
1086
1087/*
1088 expect(mi.lcField()).toEqual(' baum');
1089*/
1090
1091 });
1092
1093 it('should be modifiable', function () {
1094 var p = prefixClass.create();
1095 expect(p.value()).toEqual('');
1096 expect(p.element().firstChild).toBeNull();
1097
1098 // Set string
1099 expect(p.value('Test')).toEqual('Test');
1100 expect(p.value()).toEqual('Test');
1101 expect(p.element().firstChild.nodeValue).toEqual('Test');
1102
1103 // Add string
1104 expect(p.add('ified')).toEqual('Testified');
1105 expect(p.value()).toEqual('Testified');
1106 expect(p.element().firstChild.nodeValue).toEqual('Testified');
1107
1108 // Clear string
1109 p.clear();
1110 expect(p.value()).toEqual('');
1111 expect(p.element().firstChild).toBeNull();
1112
1113 // Set string
1114 expect(p.value('Test')).toEqual('Test');
1115 expect(p.value()).toEqual('Test');
1116 expect(p.element().firstChild.nodeValue).toEqual('Test');
1117
1118 expect(p.chop()).toEqual('Tes');
1119 expect(p.value()).toEqual('Tes');
1120 expect(p.element().firstChild.nodeValue).toEqual('Tes');
1121
1122 expect(p.chop()).toEqual('Te');
1123 expect(p.value()).toEqual('Te');
1124 expect(p.element().firstChild.nodeValue).toEqual('Te');
1125
1126 expect(p.chop()).toEqual('T');
1127 expect(p.value()).toEqual('T');
1128 expect(p.element().firstChild.nodeValue).toEqual('T');
1129
1130 expect(p.chop()).toEqual('');
1131 expect(p.value()).toEqual('');
1132 expect(p.element().firstChild).toBeNull();
1133 });
1134
1135 it('should be activatable', function () {
1136 var p = prefixClass.create();
1137 expect(p.value()).toEqual('');
1138 expect(p.element().firstChild).toBeNull();
1139
1140 expect(p.value('Test')).toEqual('Test');
1141 expect(p.element().firstChild.nodeValue).toEqual('Test');
1142
1143 expect(p.active()).not.toBeTruthy();
1144 expect(p.element().classList.contains('active')).not.toBeTruthy();
1145
1146 p.active(true);
1147 expect(p.active()).toBeTruthy();
1148 expect(p.element().classList.contains('active')).toBeTruthy();
1149 });
Nils Diewaldfda29d92015-01-22 17:28:01 +00001150 });
Akronc7448732016-04-27 14:06:58 +02001151
1152 describe('KorAP.LengthField', function () {
1153 it('should be initializable', function () {
1154 var l = lengthFieldClass.create();
1155 expect(l.element().classList.contains('lengthField')).toBeTruthy();
1156 expect(l.element().children.length).toEqual(0);
1157 });
1158
1159 it('should be extensible', function () {
1160 var l = lengthFieldClass.create();
Akron1ff3ac22016-04-28 16:30:45 +02001161 l.add(['Baum']);
Akronc7448732016-04-27 14:06:58 +02001162 expect(l.element().children.length).toEqual(1);
1163 expect(l.element().children[0].nodeName).toEqual('SPAN');
Akron1ff3ac22016-04-28 16:30:45 +02001164 expect(l.element().children[0].textContent).toEqual('Baum--');
1165 l.add(['Fragezeichen']);
Akronc7448732016-04-27 14:06:58 +02001166 expect(l.element().children.length).toEqual(2);
1167 expect(l.element().children[1].nodeName).toEqual('SPAN');
Akron1ff3ac22016-04-28 16:30:45 +02001168 expect(l.element().children[1].textContent).toEqual('Fragezeichen--');
Akronc7448732016-04-27 14:06:58 +02001169 });
1170
1171 it('should be correctly initializable', function () {
1172 var list = [
1173 ["Constituency"],
1174 ["Lemma"],
1175 ["Morphology"],
1176 ["Part-of-Speech"],
1177 ["Syntax"]
1178 ];
1179
1180 var menu = KorAP.OwnMenu.create(list);
1181
1182 expect(menu.lengthField().element().children.length).toEqual(5);
1183 });
1184 });
Akronf86eaea2016-05-13 18:02:27 +02001185
1186 describe('KorAP.Slider', function () {
1187 it('should be correctly initializable', function () {
1188 var list = [
1189 ["Constituency"],
1190 ["Lemma"],
1191 ["Morphology"],
1192 ["Part-of-Speech"],
1193 ["Syntax"]
1194 ];
1195
1196 var menu = KorAP.OwnMenu.create(list);
1197
1198 menu._firstActive = true;
1199 menu.limit(3);
1200
1201 expect(menu.show()).toBe(true);
1202
1203 expect(menu.shownItem(0).active()).toBe(true);
1204 expect(menu.shownItem(1).active()).toBe(false);
1205 expect(menu.shownItem(2).active()).toBe(false);
1206 expect(menu.slider().offset()).toEqual(0);
1207 expect(menu.position).toEqual(0);
1208
1209 menu.next();
1210 expect(menu.shownItem(0).active()).toBe(false);
1211 expect(menu.shownItem(1).active()).toBe(true);
1212 expect(menu.shownItem(2).active()).toBe(false);
1213 expect(menu.slider().offset()).toEqual(0);
1214 expect(menu.position).toEqual(1);
1215
1216 menu.next();
1217 expect(menu.shownItem(0).active()).toBe(false);
1218 expect(menu.shownItem(1).active()).toBe(false);
1219 expect(menu.shownItem(2).active()).toBe(true);
1220 expect(menu.slider().offset()).toEqual(0);
1221 expect(menu.position).toEqual(2);
1222
1223 menu.next();
1224 expect(menu.shownItem(0).active()).toBe(false);
1225 expect(menu.shownItem(1).active()).toBe(false);
1226 expect(menu.shownItem(2).active()).toBe(true);
1227 expect(menu.slider().offset()).toEqual(1);
1228 expect(menu.position).toEqual(3);
1229
1230 menu.next();
1231 expect(menu.shownItem(0).active()).toBe(false);
1232 expect(menu.shownItem(1).active()).toBe(false);
1233 expect(menu.shownItem(2).active()).toBe(true);
1234 expect(menu.slider().offset()).toEqual(2);
1235 expect(menu.position).toEqual(4);
1236
1237 menu.next();
1238 expect(menu.shownItem(0).active()).toBe(true);
1239 expect(menu.shownItem(1).active()).toBe(false);
1240 expect(menu.shownItem(2).active()).toBe(false);
1241 expect(menu.slider().offset()).toEqual(0);
1242 expect(menu.position).toEqual(0);
1243
1244 expect(menu.slider()._slider.style.height).toEqual('60%');
1245
1246 });
1247 });
Nils Diewaldfda29d92015-01-22 17:28:01 +00001248});