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