blob: 7436e4d71b7f21dfd55d14cf7c05a6bfbe821b51 [file] [log] [blame]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001define(['menu'], function () {
Nils Diewaldfda29d92015-01-22 17:28:01 +00002
Nils Diewald7c8ced22015-04-15 19:21:00 +00003 var menuItemClass = require('menu/item');
4 var menuClass = require('menu');
Nils Diewaldfda29d92015-01-22 17:28:01 +00005
Nils Diewald7c8ced22015-04-15 19:21:00 +00006 // The OwnMenu item
7 KorAP.OwnMenuItem = {
8 create : function (params) {
9 return Object.create(menuItemClass).upgradeTo(KorAP.OwnMenuItem)._init(params);
10 },
11 content : function (content) {
12 if (arguments.length === 1) {
13 this._content = content;
14 };
15 return this._content;
16 },
17 _init : function (params) {
18 if (params[0] === undefined)
19 throw new Error("Missing parameters");
20
21 this._content = document.createTextNode(params[0]);
22 this._lcField = ' ' + this.content().textContent.toLowerCase();
23
24 return this;
25 }
26 };
27
28 // The OwnMenu
29 KorAP.OwnMenu = {
30 create : function (params) {
31 return Object.create(menuClass)
32 .upgradeTo(KorAP.OwnMenu)
33 ._init(KorAP.OwnMenuItem, undefined, params);
34 }
35 };
Nils Diewaldfda29d92015-01-22 17:28:01 +000036
Nils Diewaldfda29d92015-01-22 17:28:01 +000037
Nils Diewald7c8ced22015-04-15 19:21:00 +000038 // HintMenuItem
39 KorAP.HintMenuItem = {
40 create : function (params) {
41 return Object.create(menuItemClass)
42 .upgradeTo(KorAP.HintMenuItem)
43 ._init(params);
44 },
45 content : function (content) {
46 if (arguments.length === 1) {
47 this._content = content;
48 };
49 return this._content;
50 },
51 _init : function (params) {
52 if (params[0] === undefined || params[1] === undefined)
53 throw new Error("Missing parameters");
54
55 this._name = params[0];
56 this._action = params[1];
57 this._lcField = ' ' + this._name.toLowerCase();
58
59 if (params.length > 2) {
60 this._desc = params[2];
61 this._lcField += " " + this._desc.toLowerCase();
62 };
63
64 return this;
65 },
66
67 name : function () {
68 return this._name;
69 },
70 action : function () {
71 return this._action;
72 },
73 desc : function () {
74 return this._desc;
75 },
76 element : function () {
77 // already defined
78 if (this._element !== undefined)
79 return this._element;
80
81 // Create list item
82 var li = document.createElement("li");
83 li.setAttribute("data-action", this._action);
84
85 // Create title
86 var name = document.createElement("strong");
87 name.appendChild(document.createTextNode(this._name));
88
89 li.appendChild(name);
90
91 // Create description
92 if (this._desc !== undefined) {
93 var desc = document.createElement("span");
94 desc.appendChild(document.createTextNode(this._desc));
95 li.appendChild(desc);
96 };
97 return this._element = li;
98 }
99 };
Nils Diewald86dad5b2015-01-28 15:09:07 +0000100
101
Nils Diewald7c8ced22015-04-15 19:21:00 +0000102 // HintMenu
103 KorAP.HintMenu = {
104 create : function (context, params) {
105 var obj = Object.create(menuClass)
106 .upgradeTo(KorAP.HintMenu)
107 ._init(KorAP.HintMenuItem, undefined, params);
108 obj._context = context;
109 return obj;
110 }
111 };
Nils Diewald86dad5b2015-01-28 15:09:07 +0000112
113
Nils Diewald7c8ced22015-04-15 19:21:00 +0000114 // The ComplexMenuItem
115 KorAP.ComplexMenuItem = {
116 create : function (params) {
117 return Object.create(menuItemClass)
118 .upgradeTo(KorAP.ComplexMenuItem)
119 ._init(params);
120 },
121 content : function (content) {
122 if (arguments.length === 1) {
123 this._content = content;
124 };
125 return this._content;
126 },
127 _init : function (params) {
128 if (params[0] === undefined)
129 throw new Error("Missing parameters");
130
131 var r = document.createElement('div');
132 for (var i = 1; i <= params.length; i++) {
133 var h = document.createElement('h' + i);
134 h.appendChild(document.createTextNode(params[i-1]));
135 r.appendChild(h);
136 };
137
138 this._content = r;
139 this._lcField = ' ' + this.content().textContent.toLowerCase();
140
141 return this;
142 }
143 };
Nils Diewald2fe12e12015-03-06 16:47:06 +0000144
145
Nils Diewald7c8ced22015-04-15 19:21:00 +0000146 describe('KorAP.MenuItem', function () {
147 it('should be initializable', function () {
148 expect(
149 function() { menuItemClass.create([]) }
150 ).toThrow(new Error("Missing parameters"));
Nils Diewald2fe12e12015-03-06 16:47:06 +0000151
Nils Diewald7c8ced22015-04-15 19:21:00 +0000152 expect(
153 function() { KorAP.OwnMenuItem.create([]) }
154 ).toThrow(new Error("Missing parameters"));
Nils Diewald2fe12e12015-03-06 16:47:06 +0000155
Nils Diewald7c8ced22015-04-15 19:21:00 +0000156 var mi = KorAP.OwnMenuItem.create(["Baum"]);
157 expect(mi.element().firstChild.nodeValue).toEqual('Baum');
158 expect(mi.lcField()).toEqual(' baum');
159 });
Nils Diewald2fe12e12015-03-06 16:47:06 +0000160
Nils Diewald7c8ced22015-04-15 19:21:00 +0000161 it('shouldn\'t have a reference to the menu', function () {
162 var menuItem = KorAP.OwnMenuItem.create(['Test']);
163 expect(menuItem.menu()).toBe(undefined);
164 });
165
166 it('should be activatable and deactivateable by class', function () {
167 var menuItem = KorAP.OwnMenuItem.create(['Test']);
168
169 expect(menuItem.active()).toBe(false);
170 expect(menuItem.element().getAttribute("class")).toBe(null);
171 menuItem.active(true);
172 expect(menuItem.active()).toBe(true);
173 expect(menuItem.element().getAttribute("class")).toEqual("active");
174 menuItem.active(false); // Is active
175 expect(menuItem.active()).toBe(false);
176 expect(menuItem.element().getAttribute("class")).toEqual("");
177 menuItem.active(true);
178 expect(menuItem.active()).toBe(true);
179 expect(menuItem.element().getAttribute("class")).toEqual("active");
180
181 menuItem = KorAP.OwnMenuItem.create(['Spiegel']);
182 expect(menuItem.active()).toBe(false);
183 expect(menuItem.element().getAttribute("class")).toBe(null);
184 menuItem.active(false); // Is not active
185 expect(menuItem.active()).toBe(false);
186 expect(menuItem.element().getAttribute("class")).toBe(null);
187 });
188
189 it('should be set to boundary', function () {
190 var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']);
191 expect(menuItem.active()).toBe(false);
192 expect(menuItem.element().getAttribute("class")).toBe(null);
193
194 // Set active
195 menuItem.active(true);
196 expect(menuItem.active()).toBe(true);
197 expect(menuItem.noMore()).toBe(false);
198 expect(menuItem.element().getAttribute("class")).toEqual("active");
199
200 // Set no more
201 menuItem.noMore(true);
202 expect(menuItem.active()).toBe(true);
203 expect(menuItem.noMore()).toBe(true);
204 expect(menuItem.element().getAttribute("class")).toEqual("active no-more");
205
206 // No no more
207 menuItem.noMore(false);
208 expect(menuItem.active()).toBe(true);
209 expect(menuItem.noMore()).toBe(false);
210 expect(menuItem.element().getAttribute("class")).toEqual("active");
211
212 // Set no more, deactivate
213 menuItem.noMore(true);
214 menuItem.active(false);
215 expect(menuItem.active()).toBe(false);
216 expect(menuItem.noMore()).toBe(true);
217 expect(menuItem.element().getAttribute("class")).toEqual("no-more");
218
219 // Set active
220 menuItem.active(true);
221 expect(menuItem.active()).toBe(true);
222 expect(menuItem.noMore()).toBe(true);
223 expect(menuItem.element().getAttribute("class")).toEqual("no-more active");
224 });
Nils Diewald2fe12e12015-03-06 16:47:06 +0000225
226
Nils Diewald7c8ced22015-04-15 19:21:00 +0000227 it('should be highlightable', function () {
228 // Highlight in the middle
229 var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']);
230 menuItem.highlight("ren");
231 expect(menuItem.element().innerHTML).toEqual("Co<mark>reN</mark>LP");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000232
Nils Diewald7c8ced22015-04-15 19:21:00 +0000233 menuItem.lowlight();
234 expect(menuItem.element().innerHTML).toEqual("CoreNLP");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000235
Nils Diewald7c8ced22015-04-15 19:21:00 +0000236 var plain = "<div><h1>CoreNLP</h1><h2>corenlp/</h2></div>";
Nils Diewaldfda29d92015-01-22 17:28:01 +0000237
Nils Diewald7c8ced22015-04-15 19:21:00 +0000238 // Starting highlight
239 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
240 menuItem.highlight("cor");
241 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 +0000242
Nils Diewald7c8ced22015-04-15 19:21:00 +0000243 menuItem.lowlight();
244 expect(menuItem.element().innerHTML).toEqual(plain);
Nils Diewald6e43ffd2015-03-25 18:55:39 +0000245
Nils Diewald7c8ced22015-04-15 19:21:00 +0000246 // Starting highlight - short
247 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
248 menuItem.highlight("c");
249 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 +0000250
Nils Diewald7c8ced22015-04-15 19:21:00 +0000251 menuItem.lowlight();
252 expect(menuItem.element().innerHTML).toEqual(plain);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000253
Nils Diewald7c8ced22015-04-15 19:21:00 +0000254 // Highlight at the end
255 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
256 menuItem.highlight("nlp");
257 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 +0000258
Nils Diewald7c8ced22015-04-15 19:21:00 +0000259 menuItem.lowlight();
260 expect(menuItem.element().innerHTML).toEqual(plain);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000261
Nils Diewald7c8ced22015-04-15 19:21:00 +0000262 // Highlight at the end - short
263 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
264 menuItem.highlight("p");
265 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 +0000266
Nils Diewald7c8ced22015-04-15 19:21:00 +0000267 menuItem.lowlight();
268 expect(menuItem.element().innerHTML).toEqual(plain);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000269
Nils Diewald7c8ced22015-04-15 19:21:00 +0000270 // No highlight
271 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
272 menuItem.highlight("xp");
273 expect(menuItem.element().innerHTML).toEqual(plain);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000274
Nils Diewald7c8ced22015-04-15 19:21:00 +0000275 menuItem.lowlight();
276 expect(menuItem.element().innerHTML).toEqual(plain);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000277
Nils Diewald7c8ced22015-04-15 19:21:00 +0000278 // Highlight in the middle - first
279 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
280 menuItem.highlight("ren");
281 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>");
282
283 plain = "<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Example</h3></div>"
284
285 menuItem.lowlight();
286 expect(menuItem.element().innerHTML).toEqual(plain);
287
288 // Highlight in the middle - second
289 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
290 menuItem.highlight("ampl");
291 expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Ex<mark>ampl</mark>e</h3></div>");
292
293 menuItem.lowlight();
294 expect(menuItem.element().innerHTML).toEqual(plain);
295
296 // Highlight in the middle - both
297 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
298 menuItem.highlight("e");
299 expect(menuItem.element().innerHTML).toEqual("<div><h1>Cor<mark>e</mark>NLP</h1><h2>cor<mark>e</mark>nlp/</h2><h3>This is my <mark>E</mark>xampl<mark>e</mark></h3></div>");
300
301 menuItem.lowlight();
302 expect(menuItem.element().innerHTML).toEqual(plain);
303
304 // Highlight in the end - second
305 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
306 menuItem.highlight("le");
307 expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Examp<mark>le</mark></h3></div>");
308
309 menuItem.lowlight();
310 expect(menuItem.element().innerHTML).toEqual(plain);
311
312 // Highlight at the beginning - second
313 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
314 menuItem.highlight("this");
315 expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3><mark>This</mark> is my Example</h3></div>");
316
317 menuItem.lowlight();
318 expect(menuItem.element().innerHTML).toEqual(plain);
319 });
Nils Diewaldfda29d92015-01-22 17:28:01 +0000320 });
321
322
Nils Diewald7c8ced22015-04-15 19:21:00 +0000323 describe('KorAP.Menu', function () {
Nils Diewald86dad5b2015-01-28 15:09:07 +0000324 var list = [
Nils Diewald7c8ced22015-04-15 19:21:00 +0000325 ["Constituency", "c=", "Example 1"],
326 ["Lemma", "l="],
327 ["Morphology", "m=", "Example 2"],
328 ["Part-of-Speech", "p="],
329 ["Syntax", "syn="]
Nils Diewald86dad5b2015-01-28 15:09:07 +0000330 ];
Nils Diewaldfda29d92015-01-22 17:28:01 +0000331
Nils Diewald7c8ced22015-04-15 19:21:00 +0000332 var demolist = [
333 ['Titel', 'title'],
334 ['Untertitel', 'subTitle'],
335 ['Veröffentlichungsdatum', 'pubDate'],
336 ['Länge', 'length'],
337 ['Autor', 'author']
338 ];
Nils Diewaldfda29d92015-01-22 17:28:01 +0000339
Nils Diewald7c8ced22015-04-15 19:21:00 +0000340 var demolonglist = [
341 ['Titel', 'title'],
342 ['Untertitel', 'subTitle'],
343 ['Veröffentlichungsdatum', 'pubDate'],
344 ['Länge', 'length'],
345 ['Autor', 'author'],
346 ['Genre', 'genre'],
347 ['corpusID', 'corpusID'],
348 ['docID', 'docID'],
349 ['textID', 'textID'],
350 ];
Nils Diewald86dad5b2015-01-28 15:09:07 +0000351
Nils Diewald7c8ced22015-04-15 19:21:00 +0000352 it('should be initializable', function () {
353 var list = [
354 ["Constituency"],
355 ["Lemma"],
356 ["Morphology"],
357 ["Part-of-Speech"],
358 ["Syntax"]
359 ];
Nils Diewaldfda29d92015-01-22 17:28:01 +0000360
Nils Diewald7c8ced22015-04-15 19:21:00 +0000361 var menu = KorAP.OwnMenu.create(list);
362 expect(menu.itemClass()).toEqual(KorAP.OwnMenuItem);
363 expect(menu.element().nodeName).toEqual('UL');
364 expect(menu.element().style.opacity).toEqual("0");
365 expect(menu.limit()).toEqual(8);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000366
Nils Diewald7c8ced22015-04-15 19:21:00 +0000367 menu.limit(9);
368 expect(menu.limit()).toEqual(9);
Nils Diewald86dad5b2015-01-28 15:09:07 +0000369
Nils Diewald7c8ced22015-04-15 19:21:00 +0000370 menu.limit(8);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000371
Nils Diewald7c8ced22015-04-15 19:21:00 +0000372 // view
373 menu.show();
374
375 // First element in list
376 expect(menu.item(0).active()).toBe(true);
377 expect(menu.item(0).noMore()).toBe(true);
378
379 // Middle element in list
380 expect(menu.item(2).active()).toBe(false);
381 expect(menu.item(2).noMore()).toBe(false);
382
383 // Last element in list
384 expect(menu.item(menu.length() - 1).active()).toBe(false);
385 expect(menu.item(menu.length() - 1).noMore()).toBe(true);
386 });
387
388 it('should have a reference to the menu', function () {
389 var menu = KorAP.HintMenu.create("cnx/", list);
390 expect(menu.item(0).menu()).toEqual(menu);
391
392 menu = KorAP.HintMenu.create("cnx/", list);
393 expect(menu.element().menu).toEqual(menu);
394 });
395
396
397 it('should be visible', function () {
398 var menu = KorAP.HintMenu.create("cnx/", list);
399 expect(menu.delete()).toBe(undefined);
400 menu.limit(3);
401
402 expect(menu.show()).toBe(true);
403
404 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
405 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
406 expect(menu.element().childNodes[2].getAttribute("data-action")).toEqual("l=");
407 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
408 expect(menu.element().childNodes[4]).toBe(undefined);
409
410 // Check boundaries
411 expect(menu.element().childNodes[1].classList.contains("no-more")).toBe(true);
412 expect(menu.element().childNodes[2].classList.contains("no-more")).toBe(false);
413 expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(false);
414 });
415
416 it('should be filterable', function () {
417 var menu = KorAP.HintMenu.create("cnx/", list);
418 menu.limit(3);
419 expect(menu.prefix("o").show()).toBe(true);
420 expect(menu.element().childNodes[0].innerHTML).toEqual("o");
421 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
422 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
423 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
424 expect(menu.element().childNodes[4]).toBe(undefined);
425
426 // Check boundaries
427 expect(menu.element().childNodes[1].classList.contains("no-more")).toBe(true);
428 expect(menu.element().childNodes[2].classList.contains("no-more")).toBe(false);
429 expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(true);
430
431 menu.limit(2);
432
433 expect(menu.prefix("o").show()).toBe(true);
434 expect(menu.element().childNodes[0].innerHTML).toEqual("o");
435 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
436 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
437 expect(menu.element().childNodes[3]).toBe(undefined);
438
439 // Check boundaries
440 expect(menu.element().childNodes[1].classList.contains("no-more")).toBe(true);
441 expect(menu.element().childNodes[2].classList.contains("no-more")).toBe(false);
442 expect(menu.element().childNodes[3]).toBe(undefined);
443
444 expect(menu.prefix("e").show()).toBe(true);
445 expect(menu.element().childNodes[0].innerHTML).toEqual("e");
446 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
447 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
448 expect(menu.element().childNodes[3]).toBe(undefined);
449
450 menu.limit(5);
451 expect(menu.prefix("a").show()).toBe(true);
452 expect(menu.element().childNodes[0].innerHTML).toEqual("a");
453 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Ex<mark>a</mark>mple 1</span>");
454 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemm<mark>a</mark></strong>");
455 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Ex<mark>a</mark>mple 2</span>");
456 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>P<mark>a</mark>rt-of-Speech</strong>");
457 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Synt<mark>a</mark>x</strong>");
458 expect(menu.element().childNodes[6]).toBe(undefined);
459 });
460
461
462 it('should be nextable', function () {
463 var menu = KorAP.HintMenu.create("cnx/", list);
464
465 // Show only 3 items
466 menu.limit(3);
467 expect(menu.show()).toBe(true);
468 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
469 expect(menu.shownItem(0).active()).toBe(true);
470 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
471 expect(menu.shownItem(1).active()).toBe(false);
472 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
473 expect(menu.shownItem(2).active()).toBe(false);
474 expect(menu.element().childNodes[4]).toBe(undefined);
475
476 // Activate next (1)
477 menu.next();
478 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
479 expect(menu.shownItem(0).active()).toBe(false);
480 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
481 expect(menu.shownItem(1).active()).toBe(true);
482 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
483 expect(menu.shownItem(2).active()).toBe(false);
484 expect(menu.element().childNodes[4]).toBe(undefined);
485
486 // Activate next (2)
487 menu.next();
488 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
489 expect(menu.shownItem(0).active()).toBe(false);
490 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
491 expect(menu.shownItem(1).active()).toBe(false);
492 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
493 expect(menu.shownItem(2).active()).toBe(true);
494 expect(menu.element().childNodes[4]).toBe(undefined);
495
496 // Activate next (3)
497 // scroll!
498 menu.next();
499 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Lemma</strong>");
500 expect(menu.shownItem(0).active()).toBe(false);
501 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
502 expect(menu.shownItem(1).active()).toBe(false);
503 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
504 expect(menu.shownItem(2).active()).toBe(true);
505 expect(menu.element().childNodes[4]).toBe(undefined);
506
507 // Activate next (4)
508 menu.next();
509 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
510 expect(menu.shownItem(0).active()).toBe(false);
511 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
512 expect(menu.shownItem(1).active()).toBe(false);
513 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Syntax</strong>");
514 expect(menu.shownItem(2).active()).toBe(true);
515 expect(menu.element().childNodes[4]).toBe(undefined);
516
517 // Activate next (5) - ROLL
518 menu.next();
519 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
520 expect(menu.shownItem(0).active()).toBe(true);
521 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
522 expect(menu.shownItem(1).active()).toBe(false);
523 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
524 expect(menu.shownItem(2).active()).toBe(false);
525 expect(menu.element().childNodes[4]).toBe(undefined);
526
527 // Active next (6)
528 menu.next();
529 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
530 expect(menu.shownItem(0).active()).toBe(false);
531 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
532 expect(menu.shownItem(1).active()).toBe(true);
533 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
534 expect(menu.shownItem(2).active()).toBe(false);
535 expect(menu.element().childNodes[4]).toBe(undefined);
536 });
537
538 it('should be prevable', function () {
539 var menu = KorAP.HintMenu.create("cnx/", list);
540 menu.limit(3);
541 expect(menu.show()).toBe(true);
542
543 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
544 expect(menu.shownItem(0).active()).toBe(true);
545 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
546 expect(menu.shownItem(1).active()).toBe(false);
547 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
548 expect(menu.shownItem(2).active()).toBe(false);
549 expect(menu.element().childNodes[4]).toBe(undefined);
550
551 // Activate prev (1) - roll to bottom
552 menu.prev();
553 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
554 expect(menu.shownItem(0).active()).toBe(false);
555 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
556 expect(menu.shownItem(1).active()).toBe(false);
557 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Syntax</strong>");
558 expect(menu.shownItem(2).active()).toBe(true);
559 expect(menu.element().childNodes[4]).toBe(undefined);
560
561 // Activate prev (2)
562 menu.prev();
563 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
564 expect(menu.shownItem(0).active()).toBe(false);
565 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
566 expect(menu.shownItem(1).active()).toBe(true);
567 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Syntax</strong>");
568 expect(menu.shownItem(2).active()).toBe(false);
569 expect(menu.element().childNodes[4]).toBe(undefined);
570
571 // Activate prev (3)
572 menu.prev();
573 expect(menu.shownItem(0).name()).toEqual("Morphology");
574 expect(menu.shownItem(0).active()).toBe(true);
575 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
576 expect(menu.shownItem(1).active()).toBe(false);
577 expect(menu.shownItem(2).name()).toEqual("Syntax");
578 expect(menu.shownItem(2).active()).toBe(false);
579 expect(menu.element().childNodes[4]).toBe(undefined);
580
581 // Activate prev (4)
582 menu.prev();
583 expect(menu.shownItem(0).name()).toEqual("Lemma");
584 expect(menu.shownItem(0).active()).toBe(true);
585 expect(menu.shownItem(1).name()).toEqual("Morphology");
586 expect(menu.shownItem(1).active()).toBe(false);
587 expect(menu.shownItem(2).name()).toEqual("Part-of-Speech");
588 expect(menu.shownItem(2).active()).toBe(false);
589 expect(menu.element().childNodes[4]).toBe(undefined);
590
591 // Activate prev (5)
592 menu.prev();
593 expect(menu.shownItem(0).name()).toEqual("Constituency");
594 expect(menu.shownItem(0).active()).toBe(true);
595 expect(menu.shownItem(1).name()).toEqual("Lemma");
596 expect(menu.shownItem(1).active()).toBe(false);
597 expect(menu.shownItem(2).name()).toEqual("Morphology");
598 expect(menu.shownItem(2).active()).toBe(false);
599 expect(menu.element().childNodes[4]).toBe(undefined);
600
601 // Activate next (1)
602 menu.next();
603 expect(menu.shownItem(0).name()).toEqual("Constituency");
604 expect(menu.shownItem(0).active()).toBe(false);
605 expect(menu.shownItem(1).name()).toEqual("Lemma");
606 expect(menu.shownItem(1).active()).toBe(true);
607 expect(menu.shownItem(2).name()).toEqual("Morphology");
608 expect(menu.shownItem(2).active()).toBe(false);
609 expect(menu.element().childNodes[4]).toBe(undefined);
610
611 // Activate prev (6)
612 menu.prev();
613
614 // Activate prev (7)
615 menu.prev();
616 expect(menu.shownItem(0).name()).toEqual("Morphology");
617 expect(menu.shownItem(0).active()).toBe(false);
618 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
619 expect(menu.shownItem(1).active()).toBe(false);
620 expect(menu.shownItem(2).name()).toEqual("Syntax");
621 expect(menu.shownItem(2).active()).toBe(true);
622 expect(menu.element().childNodes[4]).toBe(undefined);
623 });
624
625
626 it('should be navigatable and filterable (prefix = "o")', function () {
627 var menu = KorAP.HintMenu.create("cnx/", list);
628 menu.limit(2);
629
630 expect(menu.prefix("o").show()).toBe(true);
631 expect(menu.shownItem(0).name()).toEqual("Constituency");
632 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
633 expect(menu.shownItem(0).active()).toBe(true);
634 expect(menu.shownItem(1).name()).toEqual("Morphology");
635 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
636 expect(menu.shownItem(1).active()).toBe(false);
637 expect(menu.shownItem(2)).toBe(undefined);
638
639 // Next (1)
640 menu.next();
641 expect(menu.shownItem(0).name()).toEqual("Constituency");
642 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
643 expect(menu.shownItem(0).active()).toBe(false);
644 expect(menu.shownItem(1).name()).toEqual("Morphology");
645 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
646 expect(menu.shownItem(1).active()).toBe(true);
647 expect(menu.shownItem(2)).toBe(undefined);
648
649 // Next (2)
650 menu.next();
651 expect(menu.shownItem(0).name()).toEqual("Morphology");
652 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
653 expect(menu.shownItem(0).active()).toBe(false);
654 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
655 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
656 expect(menu.shownItem(1).active()).toBe(true);
657 expect(menu.shownItem(2)).toBe(undefined);
658
659 // Next (3) - to prefix
660 menu.next();
661 expect(menu.shownItem(0).name()).toEqual("Morphology");
662 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
663 expect(menu.shownItem(0).active()).toBe(false);
664 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
665 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
666 expect(menu.shownItem(1).active()).toBe(false);
667 expect(menu.shownItem(2)).toBe(undefined);
668
669 menu.next();
670 expect(menu.shownItem(0).name()).toEqual("Constituency");
671 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
672 expect(menu.shownItem(0).active()).toBe(true);
673 expect(menu.shownItem(1).name()).toEqual("Morphology");
674 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
675 expect(menu.shownItem(1).active()).toBe(false);
676 expect(menu.shownItem(2)).toBe(undefined);
677 });
678
679
680 it('should be navigatable and filterable (prefix = "ex", "e")', function () {
681 var menu = KorAP.HintMenu.create("cnx/", list);
682
683 menu.limit(2);
684 expect(menu.prefix("ex").show()).toBe(true);
685
686 expect(menu.shownItem(0).name()).toEqual("Constituency");
687 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
688 expect(menu.shownItem(0).active()).toBe(true);
689 expect(menu.shownItem(1).name()).toEqual("Morphology");
690 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
691 expect(menu.shownItem(1).active()).toBe(false);
692 expect(menu.shownItem(2)).toBe(undefined);
693
694 // Next (1)
695 menu.next();
696 expect(menu.shownItem(0).name()).toEqual("Constituency");
697 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
698 expect(menu.shownItem(0).active()).toBe(false);
699 expect(menu.shownItem(1).name()).toEqual("Morphology");
700 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
701 expect(menu.shownItem(1).active()).toBe(true);
702 expect(menu.shownItem(2)).toBe(undefined);
703
704 // Next (2)
705 menu.next();
706
707 expect(menu.prefix()).toEqual('ex');
708 expect(menu.shownItem(0).name()).toEqual("Constituency");
709 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
710 expect(menu.shownItem(0).active()).toBe(false);
711
712 expect(menu.shownItem(1).name()).toEqual("Morphology");
713 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
714 expect(menu.shownItem(1).active()).toBe(false);
715 expect(menu.shownItem(2)).toBe(undefined);
716
717 // Reset limit
718 menu.limit(5);
719
720 // Change show
721 expect(menu.prefix("e").show()).toBe(true);
722 expect(menu._prefix.active()).toBe(false);
723 expect(menu.shownItem(0).name()).toEqual("Constituency");
724 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
725 expect(menu.shownItem(0).active()).toBe(true);
726 expect(menu.shownItem(1).name()).toEqual("Morphology");
727 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
728 expect(menu.shownItem(1).active()).toBe(false);
729 expect(menu.shownItem(2)).toBe(undefined);
730
731 // Next (1)
732 menu.next();
733 expect(menu._prefix.active()).toBe(false);
734 expect(menu.prefix()).toEqual('e');
735 expect(menu.shownItem(0).name()).toEqual("Constituency");
736 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
737 expect(menu.shownItem(0).active()).toBe(false);
738 expect(menu.shownItem(1).name()).toEqual("Morphology");
739 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
740 expect(menu.shownItem(1).active()).toBe(true);
741 expect(menu.shownItem(2)).toBe(undefined);
742
743 // Next (2)
744 menu.next();
745 expect(menu._prefix.active()).toBe(true);
746 expect(menu.shownItem(0).name()).toEqual("Constituency");
747 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
748 expect(menu.shownItem(0).active()).toBe(false);
749 expect(menu.shownItem(1).name()).toEqual("Morphology");
750 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
751 expect(menu.shownItem(1).active()).toBe(false);
752 expect(menu.shownItem(2)).toBe(undefined);
753
754 // Next (3)
755 menu.next();
756 expect(menu._prefix.active()).toBe(false);
757 expect(menu.shownItem(0).name()).toEqual("Constituency");
758 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
759 expect(menu.shownItem(0).active()).toBe(true);
760 expect(menu.shownItem(1).name()).toEqual("Morphology");
761 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
762 expect(menu.shownItem(1).active()).toBe(false);
763 expect(menu.shownItem(2)).toBe(undefined);
764 });
765
766
767 it('shouldn\'t be viewable with failing prefix', function () {
768 var menu = KorAP.HintMenu.create("cnx/", list);
769 menu.limit(2);
770 expect(menu.prefix("exit").show()).toBe(false);
771 });
772
773 it('should be navigatable with prefix', function () {
774 var menu = KorAP.HintMenu.create("cnx/", demolist);
775 menu.limit(3);
776
777 expect(menu.show()).toBe(true);
778 expect(menu.prefix()).toEqual("");
779
780 expect(menu.shownItem(0).name()).toEqual("Titel");
781 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
782 expect(menu.shownItem(0).active()).toBe(true);
783 expect(menu.shownItem(1).name()).toEqual("Untertitel");
784 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
785 expect(menu.shownItem(1).active()).toBe(false);
786 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
787 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
788 expect(menu.shownItem(2).active()).toBe(false);
789 expect(menu.shownItem(3)).toBe(undefined);
790
791 menu._prefix.add('a');
792 expect(menu.show()).toBe(true);
793 expect(menu.prefix()).toEqual("a");
794 expect(menu.shownItem(0).name()).toEqual("Autor");
795 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
796
797 menu._prefix.add('u');
798 expect(menu.show()).toBe(true);
799 expect(menu.prefix()).toEqual("au");
800 expect(menu.shownItem(0).name()).toEqual("Autor");
801 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong><mark>Au</mark>tor</strong>");
802
803 menu._prefix.backspace();
804 expect(menu.show()).toBe(true);
805 expect(menu.prefix()).toEqual("a");
806 expect(menu.shownItem(0).name()).toEqual("Autor");
807 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
808
809 menu._prefix.backspace();
810 expect(menu.show()).toBe(true);
811 expect(menu.prefix()).toEqual("");
812 expect(menu.shownItem(0).name()).toEqual("Titel");
813 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
814 expect(menu.shownItem(0).active()).toBe(true);
815 expect(menu.shownItem(1).name()).toEqual("Untertitel");
816 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
817 expect(menu.shownItem(1).active()).toBe(false);
818 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
819 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
820 expect(menu.shownItem(2).active()).toBe(false);
821 expect(menu.shownItem(3)).toBe(undefined);
822
823 // Forward
824 menu._prefix.backspace();
825 expect(menu.show()).toBe(true);
826 expect(menu.prefix()).toEqual("");
827 expect(menu.shownItem(0).name()).toEqual("Titel");
828 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
829 expect(menu.shownItem(0).active()).toBe(true);
830 expect(menu.shownItem(1).name()).toEqual("Untertitel");
831 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
832 expect(menu.shownItem(1).active()).toBe(false);
833 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
834 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
835 expect(menu.shownItem(2).active()).toBe(false);
836
837 // Forward
838 menu.next();
839 expect(menu.prefix()).toEqual("");
840 expect(menu.shownItem(0).name()).toEqual("Titel");
841 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
842 expect(menu.shownItem(0).active()).toBe(false);
843 expect(menu.shownItem(1).name()).toEqual("Untertitel");
844 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
845 expect(menu.shownItem(1).active()).toBe(true);
846 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
847 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
848 expect(menu.shownItem(2).active()).toBe(false);
849 expect(menu.shownItem(3)).toBe(undefined);
850
851 // Forward
852 menu.next();
853 expect(menu.prefix()).toEqual("");
854 expect(menu.shownItem(0).name()).toEqual("Titel");
855 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
856 expect(menu.shownItem(0).active()).toBe(false);
857 expect(menu.shownItem(1).name()).toEqual("Untertitel");
858 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
859 expect(menu.shownItem(1).active()).toBe(false);
860 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
861 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
862 expect(menu.shownItem(2).active()).toBe(true);
863 expect(menu.shownItem(3)).toBe(undefined);
864
865 // Forward
866 menu.next();
867 expect(menu.prefix()).toEqual("");
868 expect(menu.shownItem(0).name()).toEqual("Untertitel");
869 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Untertitel</strong>");
870 expect(menu.shownItem(0).active()).toBe(false);
871 expect(menu.shownItem(1).name()).toEqual("Veröffentlichungsdatum");
872 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
873 expect(menu.shownItem(1).active()).toBe(false);
874 expect(menu.shownItem(2).name()).toEqual("Länge");
875 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Länge</strong>");
876 expect(menu.shownItem(2).active()).toBe(true);
877 expect(menu.shownItem(3)).toBe(undefined);
878
879 // Forward
880 menu.next();
881 expect(menu.prefix()).toEqual("");
882 expect(menu.shownItem(0).name()).toEqual("Veröffentlichungsdatum");
883 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
884 expect(menu.shownItem(0).active()).toBe(false);
885 expect(menu.shownItem(1).name()).toEqual("Länge");
886 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Länge</strong>");
887 expect(menu.shownItem(1).active()).toBe(false);
888 expect(menu.shownItem(2).name()).toEqual("Autor");
889 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Autor</strong>");
890 expect(menu.shownItem(2).active()).toBe(true);
891 expect(menu.shownItem(3)).toBe(undefined);
892
893 // Forward
894 menu.next();
895 expect(menu.prefix()).toEqual("");
896 expect(menu.shownItem(0).name()).toEqual("Titel");
897 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
898 expect(menu.shownItem(0).active()).toBe(true);
899 expect(menu.shownItem(1).name()).toEqual("Untertitel");
900 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
901 expect(menu.shownItem(1).active()).toBe(false);
902 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
903 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
904 expect(menu.shownItem(2).active()).toBe(false);
905 });
906
907
908 it('should be navigatable with a prefix (1)', function () {
909 var menu = KorAP.HintMenu.create("cnx/", demolist);
910 menu.limit(3);
911
912 expect(menu.show()).toBe(true);
913 expect(menu.prefix()).toEqual("");
914
915 menu.prefix('el');
916 expect(menu.show()).toBe(true);
917
918 expect(menu.prefix()).toEqual("el");
919 expect(menu._prefix.active()).toEqual(false);
920 expect(menu.shownItem(0).name()).toEqual("Titel");
921 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
922 expect(menu.shownItem(0).active()).toBe(true);
923 expect(menu.shownItem(1).name()).toEqual("Untertitel");
924 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
925 expect(menu.shownItem(1).active()).toBe(false);
926 expect(menu.shownItem(2)).toBe(undefined);
927
928 // Forward
929 menu.next();
930 expect(menu.prefix()).toEqual("el");
931 expect(menu._prefix.active()).toEqual(false);
932 expect(menu.shownItem(0).name()).toEqual("Titel");
933 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
934 expect(menu.shownItem(0).active()).toBe(false);
935 expect(menu.shownItem(1).name()).toEqual("Untertitel");
936 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
937 expect(menu.shownItem(1).active()).toBe(true);
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(true);
944 expect(menu.shownItem(0).name()).toEqual("Titel");
945 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
946 expect(menu.shownItem(0).active()).toBe(false);
947 expect(menu.shownItem(1).name()).toEqual("Untertitel");
948 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
949 expect(menu.shownItem(1).active()).toBe(false);
950 expect(menu.shownItem(2)).toBe(undefined);
951
952 // Backward
953 menu.prev();
954 expect(menu.prefix()).toEqual("el");
955 expect(menu._prefix.active()).toEqual(false);
956 expect(menu.shownItem(0).name()).toEqual("Titel");
957 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
958 expect(menu.shownItem(0).active()).toBe(false);
959
960 expect(menu.shownItem(1).name()).toEqual("Untertitel");
961 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
962 expect(menu.shownItem(1).active()).toBe(true);
963 expect(menu.shownItem(2)).toBe(undefined);
964 });
965
966
967 it('should be navigatable with a prefix (2)', function () {
968 var menu = KorAP.HintMenu.create("cnx/", demolist);
969 menu.limit(3);
970 expect(menu.show()).toBe(true);
971 expect(menu.prefix()).toEqual("");
972 menu.prefix('el');
973 expect(menu.show()).toBe(true);
974
975 expect(menu.prefix()).toEqual("el");
976 expect(menu._prefix.active()).toEqual(false);
977 expect(menu.shownItem(0).name()).toEqual("Titel");
978 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
979 expect(menu.shownItem(0).active()).toBe(true);
980 expect(menu.shownItem(1).name()).toEqual("Untertitel");
981 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
982 expect(menu.shownItem(1).active()).toBe(false);
983 expect(menu.shownItem(2)).toBe(undefined);
984
985 // Backward
986 menu.prev();
987 expect(menu._prefix.active()).toEqual(true);
988
989 expect(menu.shownItem(0).name()).toEqual("Titel");
990 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
991 expect(menu.shownItem(0).active()).toBe(false);
992
993 expect(menu.shownItem(1).name()).toEqual("Untertitel");
994 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
995 expect(menu.shownItem(1).active()).toBe(false);
996 expect(menu.shownItem(2)).toBe(undefined);
997
998 // Backward
999 menu.prev();
1000 expect(menu._prefix.active()).toEqual(false);
1001 expect(menu.shownItem(0).name()).toEqual("Titel");
1002 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1003 expect(menu.shownItem(0).active()).toBe(false);
1004 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1005 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1006 expect(menu.shownItem(1).active()).toBe(true);
1007 expect(menu.shownItem(2)).toBe(undefined);
1008 });
1009
1010 it('should be navigatable with a prefix (3)', function () {
1011 var menu = KorAP.HintMenu.create("cnx/", demolist);
1012 menu.limit(3);
1013 expect(menu.show()).toBe(true);
1014 expect(menu.prefix()).toEqual("");
1015 menu.prefix('el');
1016 expect(menu.show()).toBe(true);
1017
1018 expect(menu.prefix()).toEqual("el");
1019 expect(menu._prefix.active()).toEqual(false);
1020 expect(menu.shownItem(0).name()).toEqual("Titel");
1021 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1022 expect(menu.shownItem(0).active()).toBe(true);
1023 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1024 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1025 expect(menu.shownItem(1).active()).toBe(false);
1026 expect(menu.shownItem(2)).toBe(undefined);
1027
1028 // Backward
1029 menu.prev();
1030 expect(menu._prefix.active()).toEqual(true);
1031 expect(menu.shownItem(0).name()).toEqual("Titel");
1032 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1033 expect(menu.shownItem(0).active()).toBe(false);
1034 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1035 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1036 expect(menu.shownItem(1).active()).toBe(false);
1037 expect(menu.shownItem(2)).toBe(undefined);
1038
1039
1040 // Forward
1041 menu.next();
1042 expect(menu.prefix()).toEqual("el");
1043 expect(menu._prefix.active()).toEqual(false);
1044 expect(menu.shownItem(0).name()).toEqual("Titel");
1045 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1046 expect(menu.shownItem(0).active()).toBe(true);
1047 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1048 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1049 expect(menu.shownItem(1).active()).toBe(false);
1050 expect(menu.shownItem(2)).toBe(undefined);
1051
1052 });
1053
1054 xit('should be page downable');
1055 xit('should be page upable');
1056
1057 xit('should scroll to a chosen value')
1058 xit('should highlight a chosen value')
Nils Diewaldfda29d92015-01-22 17:28:01 +00001059 });
Nils Diewaldfda29d92015-01-22 17:28:01 +00001060});