blob: 08fea76a1f65b806e2a09b2ff19f24faed262f08 [file] [log] [blame]
Nils Diewald2fe12e12015-03-06 16:47:06 +00001// The OwnMenu item
Nils Diewaldfda29d92015-01-22 17:28:01 +00002KorAP.OwnMenuItem = {
3 create : function (params) {
4 return Object.create(KorAP.MenuItem).upgradeTo(KorAP.OwnMenuItem)._init(params);
5 },
6 content : function (content) {
7 if (arguments.length === 1) {
8 this._content = content;
9 };
10 return this._content;
11 },
12 _init : function (params) {
13 if (params[0] === undefined)
14 throw new Error("Missing parameters");
15
16 this._content = document.createTextNode(params[0]);
17 this._lcField = ' ' + this.content().textContent.toLowerCase();
18
19 return this;
20 }
21};
22
Nils Diewaldfda29d92015-01-22 17:28:01 +000023
Nils Diewald2fe12e12015-03-06 16:47:06 +000024// The OwnMenu
Nils Diewald86dad5b2015-01-28 15:09:07 +000025KorAP.OwnMenu = {
26 create : function (params) {
27 return Object.create(KorAP.Menu)
28 .upgradeTo(KorAP.OwnMenu)
Nils Diewald5975d702015-03-09 17:45:42 +000029 ._init(KorAP.OwnMenuItem, undefined, params);
Nils Diewald86dad5b2015-01-28 15:09:07 +000030 }
31};
32
33
Nils Diewald2fe12e12015-03-06 16:47:06 +000034// HintMenuItem
Nils Diewald86dad5b2015-01-28 15:09:07 +000035KorAP.HintMenuItem = {
36 create : function (params) {
37 return Object.create(KorAP.MenuItem)
38 .upgradeTo(KorAP.HintMenuItem)
39 ._init(params);
40 },
41 content : function (content) {
42 if (arguments.length === 1) {
43 this._content = content;
44 };
45 return this._content;
46 },
47 _init : function (params) {
48 if (params[0] === undefined || params[1] === undefined)
49 throw new Error("Missing parameters");
50
51 this._name = params[0];
52 this._action = params[1];
53 this._lcField = ' ' + this._name.toLowerCase();
54
55 if (params.length > 2) {
56 this._desc = params[2];
57 this._lcField += " " + this._desc.toLowerCase();
58 };
59
60 return this;
61 },
62 name : function () {
63 return this._name;
64 },
65 action : function () {
66 return this._action;
67 },
68 desc : function () {
69 return this._desc;
70 },
71 element : function () {
72 // already defined
73 if (this._element !== undefined)
74 return this._element;
75
76 // Create list item
77 var li = document.createElement("li");
78 li.setAttribute("data-action", this._action);
79
80 // Create title
81 var name = document.createElement("strong");
82 name.appendChild(document.createTextNode(this._name));
83
84 li.appendChild(name);
85
86 // Create description
87 if (this._desc !== undefined) {
88 var desc = document.createElement("span");
89 desc.appendChild(document.createTextNode(this._desc));
90 li.appendChild(desc);
91 };
92 return this._element = li;
93 }
94};
95
96
Nils Diewald2fe12e12015-03-06 16:47:06 +000097// HintMenu
98KorAP.HintMenu = {
99 create : function (context, params) {
100 var obj = Object.create(KorAP.Menu)
101 .upgradeTo(KorAP.HintMenu)
Nils Diewald5975d702015-03-09 17:45:42 +0000102 ._init(KorAP.HintMenuItem, undefined, params);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000103 obj._context = context;
104 return obj;
105 }
106};
107
108
109// The ComplexMenuItem
110KorAP.ComplexMenuItem = {
111 create : function (params) {
112 return Object.create(KorAP.MenuItem)
113 .upgradeTo(KorAP.ComplexMenuItem)
114 ._init(params);
115 },
116 content : function (content) {
117 if (arguments.length === 1) {
118 this._content = content;
119 };
120 return this._content;
121 },
122 _init : function (params) {
123 if (params[0] === undefined)
124 throw new Error("Missing parameters");
125
126 var r = document.createElement('div');
127 for (var i = 1; i <= params.length; i++) {
128 var h = document.createElement('h' + i);
129 h.appendChild(document.createTextNode(params[i-1]));
130 r.appendChild(h);
131 };
132
133 this._content = r;
134 this._lcField = ' ' + this.content().textContent.toLowerCase();
135
136 return this;
137 }
138};
139
140
Nils Diewaldfda29d92015-01-22 17:28:01 +0000141
142describe('KorAP.MenuItem', function () {
143 it('should be initializable', function () {
144 expect(
145 function() { KorAP.MenuItem.create([]) }
146 ).toThrow(new Error("Missing parameters"));
147
148 expect(
149 function() { KorAP.OwnMenuItem.create([]) }
150 ).toThrow(new Error("Missing parameters"));
151
152 var mi = KorAP.OwnMenuItem.create(["Baum"]);
153 expect(mi.element().firstChild.nodeValue).toEqual('Baum');
154 expect(mi.lcField()).toEqual(' baum');
155 });
156
157 it('should be activatable and deactivateable by class', function () {
158 var menuItem = KorAP.OwnMenuItem.create(['Test']);
159
160 expect(menuItem.active()).toBe(false);
161 expect(menuItem.element().getAttribute("class")).toBe(null);
162 menuItem.active(true);
163 expect(menuItem.active()).toBe(true);
164 expect(menuItem.element().getAttribute("class")).toEqual("active");
165 menuItem.active(false); // Is active
166 expect(menuItem.active()).toBe(false);
167 expect(menuItem.element().getAttribute("class")).toEqual("");
168 menuItem.active(true);
169 expect(menuItem.active()).toBe(true);
170 expect(menuItem.element().getAttribute("class")).toEqual("active");
171
172 menuItem = KorAP.OwnMenuItem.create(['Spiegel']);
173 expect(menuItem.active()).toBe(false);
174 expect(menuItem.element().getAttribute("class")).toBe(null);
175 menuItem.active(false); // Is not active
176 expect(menuItem.active()).toBe(false);
177 expect(menuItem.element().getAttribute("class")).toBe(null);
178 });
179
180 it('should be set to boundary', function () {
181 var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']);
182 expect(menuItem.active()).toBe(false);
183 expect(menuItem.element().getAttribute("class")).toBe(null);
184
185 // Set active
186 menuItem.active(true);
187 expect(menuItem.active()).toBe(true);
188 expect(menuItem.noMore()).toBe(false);
189 expect(menuItem.element().getAttribute("class")).toEqual("active");
190
191 // Set no more
192 menuItem.noMore(true);
193 expect(menuItem.active()).toBe(true);
194 expect(menuItem.noMore()).toBe(true);
195 expect(menuItem.element().getAttribute("class")).toEqual("active no-more");
196
197 // No no more
198 menuItem.noMore(false);
199 expect(menuItem.active()).toBe(true);
200 expect(menuItem.noMore()).toBe(false);
201 expect(menuItem.element().getAttribute("class")).toEqual("active");
202
203 // Set no more, deactivate
204 menuItem.noMore(true);
205 menuItem.active(false);
206 expect(menuItem.active()).toBe(false);
207 expect(menuItem.noMore()).toBe(true);
208 expect(menuItem.element().getAttribute("class")).toEqual("no-more");
209
210 // Set active
211 menuItem.active(true);
212 expect(menuItem.active()).toBe(true);
213 expect(menuItem.noMore()).toBe(true);
214 expect(menuItem.element().getAttribute("class")).toEqual("no-more active");
215 });
216
217
218 it('should be highlightable', function () {
219 // Highlight in the middle
220 var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']);
221 menuItem.highlight("ren");
222 expect(menuItem.element().innerHTML).toEqual("Co<mark>reN</mark>LP");
223
224 menuItem.lowlight();
225 expect(menuItem.element().innerHTML).toEqual("CoreNLP");
226
227 var plain = "<div><h1>CoreNLP</h1><h2>corenlp/</h2></div>";
228
229 // Starting highlight
230 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
231 menuItem.highlight("cor");
232 expect(menuItem.element().innerHTML).toEqual("<div><h1><mark>Cor</mark>eNLP</h1><h2><mark>cor</mark>enlp/</h2></div>");
233
234 menuItem.lowlight();
235 expect(menuItem.element().innerHTML).toEqual(plain);
236
237 // Starting highlight - short
238 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
239 menuItem.highlight("c");
240 expect(menuItem.element().innerHTML).toEqual("<div><h1><mark>C</mark>oreNLP</h1><h2><mark>c</mark>orenlp/</h2></div>");
241
242 menuItem.lowlight();
243 expect(menuItem.element().innerHTML).toEqual(plain);
244
245 // Highlight at the end
246 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
247 menuItem.highlight("nlp");
248 expect(menuItem.element().innerHTML).toEqual("<div><h1>Core<mark>NLP</mark></h1><h2>core<mark>nlp</mark>/</h2></div>");
249
250 menuItem.lowlight();
251 expect(menuItem.element().innerHTML).toEqual(plain);
252
253 // Highlight at the end - short
254 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
255 menuItem.highlight("p");
256 expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNL<mark>P</mark></h1><h2>corenl<mark>p</mark>/</h2></div>");
257
258 menuItem.lowlight();
259 expect(menuItem.element().innerHTML).toEqual(plain);
260
261 // No highlight
262 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
263 menuItem.highlight("xp");
264 expect(menuItem.element().innerHTML).toEqual(plain);
265
266 menuItem.lowlight();
267 expect(menuItem.element().innerHTML).toEqual(plain);
268
269 // Highlight in the middle - first
270 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
271 menuItem.highlight("ren");
272 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>");
273
274 plain = "<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Example</h3></div>"
275
276 menuItem.lowlight();
277 expect(menuItem.element().innerHTML).toEqual(plain);
278
279 // Highlight in the middle - second
280 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
281 menuItem.highlight("ampl");
282 expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Ex<mark>ampl</mark>e</h3></div>");
283
284 menuItem.lowlight();
285 expect(menuItem.element().innerHTML).toEqual(plain);
286
287 // Highlight in the middle - both
288 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
289 menuItem.highlight("e");
290 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>");
291
292 menuItem.lowlight();
293 expect(menuItem.element().innerHTML).toEqual(plain);
294
295 // Highlight in the end - second
296 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
297 menuItem.highlight("le");
298 expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Examp<mark>le</mark></h3></div>");
299
300 menuItem.lowlight();
301 expect(menuItem.element().innerHTML).toEqual(plain);
302
303 // Highlight at the beginning - second
304 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
305 menuItem.highlight("this");
306 expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3><mark>This</mark> is my Example</h3></div>");
307
308 menuItem.lowlight();
309 expect(menuItem.element().innerHTML).toEqual(plain);
310 });
Nils Diewaldfda29d92015-01-22 17:28:01 +0000311});
312
313
314describe('KorAP.Menu', function () {
Nils Diewald2fe12e12015-03-06 16:47:06 +0000315 var list = [
316 ["Constituency", "c=", "Example 1"],
317 ["Lemma", "l="],
318 ["Morphology", "m=", "Example 2"],
319 ["Part-of-Speech", "p="],
320 ["Syntax", "syn="]
321 ];
322
Nils Diewald5975d702015-03-09 17:45:42 +0000323 var demolist = [
324 ['Titel', 'title'],
325 ['Untertitel', 'subTitle'],
326 ['Veröffentlichungsdatum', 'pubDate'],
327 ['Länge', 'length'],
328 ['Autor', 'author']
329 ];
330
Nils Diewalde8518f82015-03-18 22:41:49 +0000331 var demolonglist = [
332 ['Titel', 'title'],
333 ['Untertitel', 'subTitle'],
334 ['Veröffentlichungsdatum', 'pubDate'],
335 ['Länge', 'length'],
336 ['Autor', 'author'],
337 ['Genre', 'genre'],
338 ['corpusID', 'corpusID'],
339 ['docID', 'docID'],
340 ['textID', 'textID'],
341 ];
342
Nils Diewaldfda29d92015-01-22 17:28:01 +0000343 it('should be initializable', function () {
Nils Diewald86dad5b2015-01-28 15:09:07 +0000344 var list = [
345 ["Constituency"],
346 ["Lemma"],
347 ["Morphology"],
348 ["Part-of-Speech"],
349 ["Syntax"]
350 ];
Nils Diewaldfda29d92015-01-22 17:28:01 +0000351
Nils Diewald86dad5b2015-01-28 15:09:07 +0000352 var menu = KorAP.OwnMenu.create(list);
353 expect(menu.itemClass()).toEqual(KorAP.OwnMenuItem);
354 expect(menu.element().nodeName).toEqual('UL');
355 expect(menu.element().style.opacity).toEqual("0");
356 expect(menu.limit()).toEqual(8);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000357
Nils Diewald86dad5b2015-01-28 15:09:07 +0000358 menu.limit(9);
359 expect(menu.limit()).toEqual(9);
360
361 menu.limit(8);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000362
363 // view
364 menu.show();
365
366 // First element in list
367 expect(menu.item(0).active()).toBe(true);
368 expect(menu.item(0).noMore()).toBe(true);
Nils Diewald86dad5b2015-01-28 15:09:07 +0000369
Nils Diewaldfda29d92015-01-22 17:28:01 +0000370 // Middle element in list
371 expect(menu.item(2).active()).toBe(false);
372 expect(menu.item(2).noMore()).toBe(false);
373
374 // Last element in list
Nils Diewald86dad5b2015-01-28 15:09:07 +0000375 expect(menu.item(menu.length() - 1).active()).toBe(false);
376 expect(menu.item(menu.length() - 1).noMore()).toBe(true);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000377 });
378
379 it('should be visible', function () {
Nils Diewald86dad5b2015-01-28 15:09:07 +0000380 var menu = KorAP.HintMenu.create("cnx/", list);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000381 expect(menu.delete()).toBe(undefined);
Nils Diewald86dad5b2015-01-28 15:09:07 +0000382 menu.limit(3);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000383
Nils Diewald59c02fc2015-03-07 01:29:09 +0000384 expect(menu.show()).toBe(true);
Nils Diewald86dad5b2015-01-28 15:09:07 +0000385
Nils Diewald5975d702015-03-09 17:45:42 +0000386 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
387 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
388 expect(menu.element().childNodes[2].getAttribute("data-action")).toEqual("l=");
389 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
390 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000391
392 // Check boundaries
Nils Diewald5975d702015-03-09 17:45:42 +0000393 expect(menu.element().childNodes[1].classList.contains("no-more")).toBe(true);
Nils Diewald86dad5b2015-01-28 15:09:07 +0000394 expect(menu.element().childNodes[2].classList.contains("no-more")).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000395 expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(false);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000396 });
397
Nils Diewaldfda29d92015-01-22 17:28:01 +0000398 it('should be filterable', function () {
Nils Diewald86dad5b2015-01-28 15:09:07 +0000399 var menu = KorAP.HintMenu.create("cnx/", list);
400 menu.limit(3);
Nils Diewald5975d702015-03-09 17:45:42 +0000401 expect(menu.prefix("o").show()).toBe(true);
402 expect(menu.element().childNodes[0].innerHTML).toEqual("o");
403 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
404 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>");
405 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
406 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000407
408 // Check boundaries
Nils Diewald5975d702015-03-09 17:45:42 +0000409 expect(menu.element().childNodes[1].classList.contains("no-more")).toBe(true);
410 expect(menu.element().childNodes[2].classList.contains("no-more")).toBe(false);
411 expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(true);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000412
Nils Diewald86dad5b2015-01-28 15:09:07 +0000413 menu.limit(2);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000414
Nils Diewald5975d702015-03-09 17:45:42 +0000415 expect(menu.prefix("o").show()).toBe(true);
416 expect(menu.element().childNodes[0].innerHTML).toEqual("o");
417 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
418 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>");
419 expect(menu.element().childNodes[3]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000420
421 // Check boundaries
Nils Diewald5975d702015-03-09 17:45:42 +0000422 expect(menu.element().childNodes[1].classList.contains("no-more")).toBe(true);
423 expect(menu.element().childNodes[2].classList.contains("no-more")).toBe(false);
424 expect(menu.element().childNodes[3]).toBe(undefined);
Nils Diewald86dad5b2015-01-28 15:09:07 +0000425
Nils Diewald5975d702015-03-09 17:45:42 +0000426 expect(menu.prefix("e").show()).toBe(true);
427 expect(menu.element().childNodes[0].innerHTML).toEqual("e");
428 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
429 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
430 expect(menu.element().childNodes[3]).toBe(undefined);
Nils Diewald86dad5b2015-01-28 15:09:07 +0000431
432 menu.limit(5);
Nils Diewald5975d702015-03-09 17:45:42 +0000433 expect(menu.prefix("a").show()).toBe(true);
434 expect(menu.element().childNodes[0].innerHTML).toEqual("a");
435 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Ex<mark>a</mark>mple 1</span>");
436 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemm<mark>a</mark></strong>");
437 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Ex<mark>a</mark>mple 2</span>");
438 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>P<mark>a</mark>rt-of-Speech</strong>");
439 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Synt<mark>a</mark>x</strong>");
440 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000441 });
442
Nils Diewald86dad5b2015-01-28 15:09:07 +0000443
Nils Diewaldfda29d92015-01-22 17:28:01 +0000444 it('should be nextable', function () {
Nils Diewald86dad5b2015-01-28 15:09:07 +0000445 var menu = KorAP.HintMenu.create("cnx/", list);
446
447 // Show only 3 items
448 menu.limit(3);
Nils Diewald59c02fc2015-03-07 01:29:09 +0000449 expect(menu.show()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000450 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000451 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000452 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000453 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000454 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000455 expect(menu.shownItem(2).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000456 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000457
458 // Activate next (1)
459 menu.next();
Nils Diewald5975d702015-03-09 17:45:42 +0000460 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000461 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000462 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000463 expect(menu.shownItem(1).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000464 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000465 expect(menu.shownItem(2).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000466 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000467
468 // Activate next (2)
469 menu.next();
Nils Diewald5975d702015-03-09 17:45:42 +0000470 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000471 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000472 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000473 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000474 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000475 expect(menu.shownItem(2).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000476 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000477
478 // Activate next (3)
Nils Diewald2fe12e12015-03-06 16:47:06 +0000479 // scroll!
Nils Diewaldfda29d92015-01-22 17:28:01 +0000480 menu.next();
Nils Diewald5975d702015-03-09 17:45:42 +0000481 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000482 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000483 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000484 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000485 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000486 expect(menu.shownItem(2).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000487 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000488
489 // Activate next (4)
490 menu.next();
Nils Diewald5975d702015-03-09 17:45:42 +0000491 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000492 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000493 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000494 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000495 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Syntax</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000496 expect(menu.shownItem(2).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000497 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000498
499 // Activate next (5) - ROLL
500 menu.next();
Nils Diewald5975d702015-03-09 17:45:42 +0000501 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000502 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000503 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000504 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000505 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000506 expect(menu.shownItem(2).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000507 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000508
509 // Active next (6)
510 menu.next();
Nils Diewald5975d702015-03-09 17:45:42 +0000511 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000512 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000513 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000514 expect(menu.shownItem(1).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000515 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000516 expect(menu.shownItem(2).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000517 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000518 });
519
Nils Diewaldfda29d92015-01-22 17:28:01 +0000520 it('should be prevable', function () {
Nils Diewald2fe12e12015-03-06 16:47:06 +0000521 var menu = KorAP.HintMenu.create("cnx/", list);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000522 menu.limit(3);
Nils Diewald59c02fc2015-03-07 01:29:09 +0000523 expect(menu.show()).toBe(true);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000524
Nils Diewald5975d702015-03-09 17:45:42 +0000525 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000526 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000527 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000528 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000529 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000530 expect(menu.shownItem(2).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000531 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000532
533 // Activate prev (1) - roll to bottom
534 menu.prev();
Nils Diewald5975d702015-03-09 17:45:42 +0000535 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000536 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000537 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000538 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000539 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Syntax</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000540 expect(menu.shownItem(2).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000541 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000542
543 // Activate prev (2)
544 menu.prev();
Nils Diewald5975d702015-03-09 17:45:42 +0000545 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000546 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000547 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000548 expect(menu.shownItem(1).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000549 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Syntax</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000550 expect(menu.shownItem(2).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000551 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000552
553 // Activate prev (3)
554 menu.prev();
Nils Diewald2fe12e12015-03-06 16:47:06 +0000555 expect(menu.shownItem(0).name()).toEqual("Morphology");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000556 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000557 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000558 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000559 expect(menu.shownItem(2).name()).toEqual("Syntax");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000560 expect(menu.shownItem(2).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000561 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000562
563 // Activate prev (4)
564 menu.prev();
Nils Diewald2fe12e12015-03-06 16:47:06 +0000565 expect(menu.shownItem(0).name()).toEqual("Lemma");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000566 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000567 expect(menu.shownItem(1).name()).toEqual("Morphology");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000568 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000569 expect(menu.shownItem(2).name()).toEqual("Part-of-Speech");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000570 expect(menu.shownItem(2).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000571 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000572
573 // Activate prev (5)
574 menu.prev();
Nils Diewald2fe12e12015-03-06 16:47:06 +0000575 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000576 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000577 expect(menu.shownItem(1).name()).toEqual("Lemma");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000578 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000579 expect(menu.shownItem(2).name()).toEqual("Morphology");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000580 expect(menu.shownItem(2).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000581 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000582
583 // Activate next (1)
584 menu.next();
Nils Diewald2fe12e12015-03-06 16:47:06 +0000585 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000586 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000587 expect(menu.shownItem(1).name()).toEqual("Lemma");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000588 expect(menu.shownItem(1).active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000589 expect(menu.shownItem(2).name()).toEqual("Morphology");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000590 expect(menu.shownItem(2).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000591 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000592
593 // Activate prev (6)
594 menu.prev();
595
596 // Activate prev (7)
597 menu.prev();
Nils Diewald2fe12e12015-03-06 16:47:06 +0000598 expect(menu.shownItem(0).name()).toEqual("Morphology");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000599 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000600 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000601 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000602 expect(menu.shownItem(2).name()).toEqual("Syntax");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000603 expect(menu.shownItem(2).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000604 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000605 });
606
Nils Diewaldfda29d92015-01-22 17:28:01 +0000607
Nils Diewald2fe12e12015-03-06 16:47:06 +0000608 it('should be navigatable and filterable (prefix = "o")', function () {
609 var menu = KorAP.HintMenu.create("cnx/", list);
610 menu.limit(2);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000611
Nils Diewald5975d702015-03-09 17:45:42 +0000612 expect(menu.prefix("o").show()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000613 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewald5975d702015-03-09 17:45:42 +0000614 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000615 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000616 expect(menu.shownItem(1).name()).toEqual("Morphology");
Nils Diewald5975d702015-03-09 17:45:42 +0000617 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>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000618 expect(menu.shownItem(1).active()).toBe(false);
619 expect(menu.shownItem(2)).toBe(undefined);
620
621 // Next (1)
622 menu.next();
Nils Diewald2fe12e12015-03-06 16:47:06 +0000623 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewald5975d702015-03-09 17:45:42 +0000624 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000625 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000626 expect(menu.shownItem(1).name()).toEqual("Morphology");
Nils Diewald5975d702015-03-09 17:45:42 +0000627 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>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000628 expect(menu.shownItem(1).active()).toBe(true);
629 expect(menu.shownItem(2)).toBe(undefined);
630
Nils Diewaldfda29d92015-01-22 17:28:01 +0000631 // Next (2)
632 menu.next();
Nils Diewald2fe12e12015-03-06 16:47:06 +0000633 expect(menu.shownItem(0).name()).toEqual("Morphology");
Nils Diewald5975d702015-03-09 17:45:42 +0000634 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>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000635 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000636 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
Nils Diewald5975d702015-03-09 17:45:42 +0000637 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000638 expect(menu.shownItem(1).active()).toBe(true);
639 expect(menu.shownItem(2)).toBe(undefined);
640
Nils Diewald5975d702015-03-09 17:45:42 +0000641 // Next (3) - to prefix
642 menu.next();
643 expect(menu.shownItem(0).name()).toEqual("Morphology");
644 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>");
645 expect(menu.shownItem(0).active()).toBe(false);
646 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
647 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
648 expect(menu.shownItem(1).active()).toBe(false);
649 expect(menu.shownItem(2)).toBe(undefined);
650
Nils Diewaldfda29d92015-01-22 17:28:01 +0000651 menu.next();
Nils Diewald2fe12e12015-03-06 16:47:06 +0000652 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewald5975d702015-03-09 17:45:42 +0000653 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000654 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000655 expect(menu.shownItem(1).name()).toEqual("Morphology");
Nils Diewald5975d702015-03-09 17:45:42 +0000656 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>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000657 expect(menu.shownItem(1).active()).toBe(false);
658 expect(menu.shownItem(2)).toBe(undefined);
659 });
660
Nils Diewald2fe12e12015-03-06 16:47:06 +0000661
Nils Diewaldfda29d92015-01-22 17:28:01 +0000662 it('should be navigatable and filterable (prefix = "ex", "e")', function () {
Nils Diewald2fe12e12015-03-06 16:47:06 +0000663 var menu = KorAP.HintMenu.create("cnx/", list);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000664
Nils Diewald2fe12e12015-03-06 16:47:06 +0000665 menu.limit(2);
Nils Diewald5975d702015-03-09 17:45:42 +0000666 expect(menu.prefix("ex").show()).toBe(true);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000667
Nils Diewald2fe12e12015-03-06 16:47:06 +0000668 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewald5975d702015-03-09 17:45:42 +0000669 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000670 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000671 expect(menu.shownItem(1).name()).toEqual("Morphology");
Nils Diewald5975d702015-03-09 17:45:42 +0000672 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000673 expect(menu.shownItem(1).active()).toBe(false);
674 expect(menu.shownItem(2)).toBe(undefined);
675
676 // Next (1)
677 menu.next();
Nils Diewald2fe12e12015-03-06 16:47:06 +0000678 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewald5975d702015-03-09 17:45:42 +0000679 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000680 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000681 expect(menu.shownItem(1).name()).toEqual("Morphology");
Nils Diewald5975d702015-03-09 17:45:42 +0000682 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000683 expect(menu.shownItem(1).active()).toBe(true);
684 expect(menu.shownItem(2)).toBe(undefined);
685
686 // Next (2)
687 menu.next();
Nils Diewald5975d702015-03-09 17:45:42 +0000688
689 expect(menu.prefix()).toEqual('ex');
Nils Diewald2fe12e12015-03-06 16:47:06 +0000690 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewald5975d702015-03-09 17:45:42 +0000691 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
692 expect(menu.shownItem(0).active()).toBe(false);
693
Nils Diewald2fe12e12015-03-06 16:47:06 +0000694 expect(menu.shownItem(1).name()).toEqual("Morphology");
Nils Diewald5975d702015-03-09 17:45:42 +0000695 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000696 expect(menu.shownItem(1).active()).toBe(false);
697 expect(menu.shownItem(2)).toBe(undefined);
698
699 // Reset limit
Nils Diewald2fe12e12015-03-06 16:47:06 +0000700 menu.limit(5);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000701
702 // Change show
Nils Diewald5975d702015-03-09 17:45:42 +0000703 expect(menu.prefix("e").show()).toBe(true);
Nils Diewalde8518f82015-03-18 22:41:49 +0000704 expect(menu._prefix.active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000705 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewald5975d702015-03-09 17:45:42 +0000706 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000707 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000708 expect(menu.shownItem(1).name()).toEqual("Morphology");
Nils Diewald5975d702015-03-09 17:45:42 +0000709 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000710 expect(menu.shownItem(1).active()).toBe(false);
711 expect(menu.shownItem(2)).toBe(undefined);
712
713 // Next (1)
714 menu.next();
Nils Diewald5975d702015-03-09 17:45:42 +0000715 expect(menu._prefix.active()).toBe(false);
716 expect(menu.prefix()).toEqual('e');
Nils Diewald2fe12e12015-03-06 16:47:06 +0000717 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewald5975d702015-03-09 17:45:42 +0000718 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000719 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000720 expect(menu.shownItem(1).name()).toEqual("Morphology");
Nils Diewald5975d702015-03-09 17:45:42 +0000721 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000722 expect(menu.shownItem(1).active()).toBe(true);
723 expect(menu.shownItem(2)).toBe(undefined);
724
725 // Next (2)
726 menu.next();
Nils Diewald5975d702015-03-09 17:45:42 +0000727 expect(menu._prefix.active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000728 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewald5975d702015-03-09 17:45:42 +0000729 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
730 expect(menu.shownItem(0).active()).toBe(false);
731 expect(menu.shownItem(1).name()).toEqual("Morphology");
732 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
733 expect(menu.shownItem(1).active()).toBe(false);
734 expect(menu.shownItem(2)).toBe(undefined);
735
736 // Next (3)
737 menu.next();
738 expect(menu._prefix.active()).toBe(false);
739 expect(menu.shownItem(0).name()).toEqual("Constituency");
740 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000741 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000742 expect(menu.shownItem(1).name()).toEqual("Morphology");
Nils Diewald5975d702015-03-09 17:45:42 +0000743 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000744 expect(menu.shownItem(1).active()).toBe(false);
745 expect(menu.shownItem(2)).toBe(undefined);
746 });
Nils Diewald5975d702015-03-09 17:45:42 +0000747
748
749 it('shouldn\'t be viewable with failing prefix', function () {
750 var menu = KorAP.HintMenu.create("cnx/", list);
751 menu.limit(2);
752 expect(menu.prefix("exit").show()).toBe(false);
753 });
754
755 it('should be navigatable with prefix', function () {
756 var menu = KorAP.HintMenu.create("cnx/", demolist);
757 menu.limit(3);
758
759 expect(menu.show()).toBe(true);
760 expect(menu.prefix()).toEqual("");
761
762 expect(menu.shownItem(0).name()).toEqual("Titel");
763 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
764 expect(menu.shownItem(0).active()).toBe(true);
765 expect(menu.shownItem(1).name()).toEqual("Untertitel");
766 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
767 expect(menu.shownItem(1).active()).toBe(false);
768 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
769 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
770 expect(menu.shownItem(2).active()).toBe(false);
771 expect(menu.shownItem(3)).toBe(undefined);
772
773 menu._prefix.add('a');
774 expect(menu.show()).toBe(true);
775 expect(menu.prefix()).toEqual("a");
776 expect(menu.shownItem(0).name()).toEqual("Autor");
777 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
778
779 menu._prefix.add('u');
780 expect(menu.show()).toBe(true);
781 expect(menu.prefix()).toEqual("au");
782 expect(menu.shownItem(0).name()).toEqual("Autor");
783 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong><mark>Au</mark>tor</strong>");
784
785 menu._prefix.backspace();
786 expect(menu.show()).toBe(true);
787 expect(menu.prefix()).toEqual("a");
788 expect(menu.shownItem(0).name()).toEqual("Autor");
789 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
790
791 menu._prefix.backspace();
792 expect(menu.show()).toBe(true);
793 expect(menu.prefix()).toEqual("");
794 expect(menu.shownItem(0).name()).toEqual("Titel");
795 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
796 expect(menu.shownItem(0).active()).toBe(true);
797 expect(menu.shownItem(1).name()).toEqual("Untertitel");
798 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
799 expect(menu.shownItem(1).active()).toBe(false);
800 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
801 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
802 expect(menu.shownItem(2).active()).toBe(false);
803 expect(menu.shownItem(3)).toBe(undefined);
804
805 // Forward
806 menu._prefix.backspace();
807 expect(menu.show()).toBe(true);
808 expect(menu.prefix()).toEqual("");
809 expect(menu.shownItem(0).name()).toEqual("Titel");
810 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
811 expect(menu.shownItem(0).active()).toBe(true);
812 expect(menu.shownItem(1).name()).toEqual("Untertitel");
813 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
814 expect(menu.shownItem(1).active()).toBe(false);
815 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
816 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
817 expect(menu.shownItem(2).active()).toBe(false);
818
819 // Forward
820 menu.next();
821 expect(menu.prefix()).toEqual("");
822 expect(menu.shownItem(0).name()).toEqual("Titel");
823 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
824 expect(menu.shownItem(0).active()).toBe(false);
825 expect(menu.shownItem(1).name()).toEqual("Untertitel");
826 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
827 expect(menu.shownItem(1).active()).toBe(true);
828 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
829 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
830 expect(menu.shownItem(2).active()).toBe(false);
831 expect(menu.shownItem(3)).toBe(undefined);
832
833 // Forward
834 menu.next();
835 expect(menu.prefix()).toEqual("");
836 expect(menu.shownItem(0).name()).toEqual("Titel");
837 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
838 expect(menu.shownItem(0).active()).toBe(false);
839 expect(menu.shownItem(1).name()).toEqual("Untertitel");
840 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
841 expect(menu.shownItem(1).active()).toBe(false);
842 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
843 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
844 expect(menu.shownItem(2).active()).toBe(true);
845 expect(menu.shownItem(3)).toBe(undefined);
846
847 // Forward
848 menu.next();
849 expect(menu.prefix()).toEqual("");
850 expect(menu.shownItem(0).name()).toEqual("Untertitel");
851 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Untertitel</strong>");
852 expect(menu.shownItem(0).active()).toBe(false);
853 expect(menu.shownItem(1).name()).toEqual("Veröffentlichungsdatum");
854 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
855 expect(menu.shownItem(1).active()).toBe(false);
856 expect(menu.shownItem(2).name()).toEqual("Länge");
857 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Länge</strong>");
858 expect(menu.shownItem(2).active()).toBe(true);
859 expect(menu.shownItem(3)).toBe(undefined);
860
861 // Forward
862 menu.next();
863 expect(menu.prefix()).toEqual("");
864 expect(menu.shownItem(0).name()).toEqual("Veröffentlichungsdatum");
865 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
866 expect(menu.shownItem(0).active()).toBe(false);
867 expect(menu.shownItem(1).name()).toEqual("Länge");
868 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Länge</strong>");
869 expect(menu.shownItem(1).active()).toBe(false);
870 expect(menu.shownItem(2).name()).toEqual("Autor");
871 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Autor</strong>");
872 expect(menu.shownItem(2).active()).toBe(true);
873 expect(menu.shownItem(3)).toBe(undefined);
874
875 // Forward
876 menu.next();
877 expect(menu.prefix()).toEqual("");
878 expect(menu.shownItem(0).name()).toEqual("Titel");
879 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
880 expect(menu.shownItem(0).active()).toBe(true);
881 expect(menu.shownItem(1).name()).toEqual("Untertitel");
882 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
883 expect(menu.shownItem(1).active()).toBe(false);
884 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
885 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
886 expect(menu.shownItem(2).active()).toBe(false);
887
888 });
889
890
891 it('should be navigatable with a prefix (1)', function () {
892 var menu = KorAP.HintMenu.create("cnx/", demolist);
893 menu.limit(3);
894
895 expect(menu.show()).toBe(true);
896 expect(menu.prefix()).toEqual("");
897
898 menu.prefix('el');
899 expect(menu.show()).toBe(true);
900
901 expect(menu.prefix()).toEqual("el");
902 expect(menu._prefix.active()).toEqual(false);
903 expect(menu.shownItem(0).name()).toEqual("Titel");
904 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
905 expect(menu.shownItem(0).active()).toBe(true);
906 expect(menu.shownItem(1).name()).toEqual("Untertitel");
907 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
908 expect(menu.shownItem(1).active()).toBe(false);
909 expect(menu.shownItem(2)).toBe(undefined);
910
911 // Forward
912 menu.next();
913 expect(menu.prefix()).toEqual("el");
914 expect(menu._prefix.active()).toEqual(false);
915 expect(menu.shownItem(0).name()).toEqual("Titel");
916 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
917 expect(menu.shownItem(0).active()).toBe(false);
918 expect(menu.shownItem(1).name()).toEqual("Untertitel");
919 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
920 expect(menu.shownItem(1).active()).toBe(true);
921 expect(menu.shownItem(2)).toBe(undefined);
922
923 // Forward
924 menu.next();
925 expect(menu.prefix()).toEqual("el");
926 expect(menu._prefix.active()).toEqual(true);
927 expect(menu.shownItem(0).name()).toEqual("Titel");
928 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
929 expect(menu.shownItem(0).active()).toBe(false);
930 expect(menu.shownItem(1).name()).toEqual("Untertitel");
931 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
932 expect(menu.shownItem(1).active()).toBe(false);
933 expect(menu.shownItem(2)).toBe(undefined);
934
935
936 // Backward
937 menu.prev();
938 expect(menu.prefix()).toEqual("el");
939 expect(menu._prefix.active()).toEqual(false);
940 expect(menu.shownItem(0).name()).toEqual("Titel");
941 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
942 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald2d210752015-03-09 19:01:15 +0000943
Nils Diewald5975d702015-03-09 17:45:42 +0000944 expect(menu.shownItem(1).name()).toEqual("Untertitel");
945 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
946 expect(menu.shownItem(1).active()).toBe(true);
947 expect(menu.shownItem(2)).toBe(undefined);
948 });
949
Nils Diewalde8518f82015-03-18 22:41:49 +0000950
Nils Diewald2d210752015-03-09 19:01:15 +0000951 it('should be navigatable with a prefix (2)', function () {
Nils Diewald5975d702015-03-09 17:45:42 +0000952 var menu = KorAP.HintMenu.create("cnx/", demolist);
953 menu.limit(3);
954 expect(menu.show()).toBe(true);
955 expect(menu.prefix()).toEqual("");
956 menu.prefix('el');
957 expect(menu.show()).toBe(true);
958
959 expect(menu.prefix()).toEqual("el");
960 expect(menu._prefix.active()).toEqual(false);
961 expect(menu.shownItem(0).name()).toEqual("Titel");
962 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
963 expect(menu.shownItem(0).active()).toBe(true);
964 expect(menu.shownItem(1).name()).toEqual("Untertitel");
965 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
966 expect(menu.shownItem(1).active()).toBe(false);
967 expect(menu.shownItem(2)).toBe(undefined);
968
969 // Backward
970 menu.prev();
971 expect(menu._prefix.active()).toEqual(true);
Nils Diewald2d210752015-03-09 19:01:15 +0000972
Nils Diewald5975d702015-03-09 17:45:42 +0000973 expect(menu.shownItem(0).name()).toEqual("Titel");
974 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
975 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald2d210752015-03-09 19:01:15 +0000976
Nils Diewald5975d702015-03-09 17:45:42 +0000977 expect(menu.shownItem(1).name()).toEqual("Untertitel");
978 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
979 expect(menu.shownItem(1).active()).toBe(false);
980 expect(menu.shownItem(2)).toBe(undefined);
981
982 // Backward
Nils Diewald5975d702015-03-09 17:45:42 +0000983 menu.prev();
984 expect(menu._prefix.active()).toEqual(false);
985 expect(menu.shownItem(0).name()).toEqual("Titel");
986 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
987 expect(menu.shownItem(0).active()).toBe(false);
988 expect(menu.shownItem(1).name()).toEqual("Untertitel");
989 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
990 expect(menu.shownItem(1).active()).toBe(true);
991 expect(menu.shownItem(2)).toBe(undefined);
Nils Diewald5975d702015-03-09 17:45:42 +0000992 });
993
Nils Diewalde8518f82015-03-18 22:41:49 +0000994 it('should be navigatable with a prefix (3)', function () {
995 var menu = KorAP.HintMenu.create("cnx/", demolist);
996 menu.limit(3);
997 expect(menu.show()).toBe(true);
998 expect(menu.prefix()).toEqual("");
999 menu.prefix('el');
1000 expect(menu.show()).toBe(true);
1001
1002 expect(menu.prefix()).toEqual("el");
1003 expect(menu._prefix.active()).toEqual(false);
1004 expect(menu.shownItem(0).name()).toEqual("Titel");
1005 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1006 expect(menu.shownItem(0).active()).toBe(true);
1007 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1008 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1009 expect(menu.shownItem(1).active()).toBe(false);
1010 expect(menu.shownItem(2)).toBe(undefined);
1011
1012 // Backward
1013 menu.prev();
1014 expect(menu._prefix.active()).toEqual(true);
1015 expect(menu.shownItem(0).name()).toEqual("Titel");
1016 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1017 expect(menu.shownItem(0).active()).toBe(false);
1018 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1019 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1020 expect(menu.shownItem(1).active()).toBe(false);
1021 expect(menu.shownItem(2)).toBe(undefined);
1022
1023
1024 // Forward
1025 menu.next();
1026 expect(menu.prefix()).toEqual("el");
1027 expect(menu._prefix.active()).toEqual(false);
1028 expect(menu.shownItem(0).name()).toEqual("Titel");
1029 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1030 expect(menu.shownItem(0).active()).toBe(true);
1031 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1032 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1033 expect(menu.shownItem(1).active()).toBe(false);
1034 expect(menu.shownItem(2)).toBe(undefined);
1035
1036 });
1037
1038 it('should be page downable', function () {
1039
1040 });
Nils Diewald5975d702015-03-09 17:45:42 +00001041 xit('should be page upable');
Nils Diewaldfda29d92015-01-22 17:28:01 +00001042});