blob: 669275368cacf45d1467012cbd9ad1b4989d9e96 [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
Nils Diewald6e43ffd2015-03-25 18:55:39 +0000157 it('shouldn\'t have a reference to the menu', function () {
158 var menuItem = KorAP.OwnMenuItem.create(['Test']);
159 expect(menuItem.menu()).toBe(undefined);
160 });
161
Nils Diewaldfda29d92015-01-22 17:28:01 +0000162 it('should be activatable and deactivateable by class', function () {
163 var menuItem = KorAP.OwnMenuItem.create(['Test']);
164
165 expect(menuItem.active()).toBe(false);
166 expect(menuItem.element().getAttribute("class")).toBe(null);
167 menuItem.active(true);
168 expect(menuItem.active()).toBe(true);
169 expect(menuItem.element().getAttribute("class")).toEqual("active");
170 menuItem.active(false); // Is active
171 expect(menuItem.active()).toBe(false);
172 expect(menuItem.element().getAttribute("class")).toEqual("");
173 menuItem.active(true);
174 expect(menuItem.active()).toBe(true);
175 expect(menuItem.element().getAttribute("class")).toEqual("active");
176
177 menuItem = KorAP.OwnMenuItem.create(['Spiegel']);
178 expect(menuItem.active()).toBe(false);
179 expect(menuItem.element().getAttribute("class")).toBe(null);
180 menuItem.active(false); // Is not active
181 expect(menuItem.active()).toBe(false);
182 expect(menuItem.element().getAttribute("class")).toBe(null);
183 });
184
185 it('should be set to boundary', function () {
186 var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']);
187 expect(menuItem.active()).toBe(false);
188 expect(menuItem.element().getAttribute("class")).toBe(null);
189
190 // Set active
191 menuItem.active(true);
192 expect(menuItem.active()).toBe(true);
193 expect(menuItem.noMore()).toBe(false);
194 expect(menuItem.element().getAttribute("class")).toEqual("active");
195
196 // Set no more
197 menuItem.noMore(true);
198 expect(menuItem.active()).toBe(true);
199 expect(menuItem.noMore()).toBe(true);
200 expect(menuItem.element().getAttribute("class")).toEqual("active no-more");
201
202 // No no more
203 menuItem.noMore(false);
204 expect(menuItem.active()).toBe(true);
205 expect(menuItem.noMore()).toBe(false);
206 expect(menuItem.element().getAttribute("class")).toEqual("active");
207
208 // Set no more, deactivate
209 menuItem.noMore(true);
210 menuItem.active(false);
211 expect(menuItem.active()).toBe(false);
212 expect(menuItem.noMore()).toBe(true);
213 expect(menuItem.element().getAttribute("class")).toEqual("no-more");
214
215 // Set active
216 menuItem.active(true);
217 expect(menuItem.active()).toBe(true);
218 expect(menuItem.noMore()).toBe(true);
219 expect(menuItem.element().getAttribute("class")).toEqual("no-more active");
220 });
221
222
223 it('should be highlightable', function () {
224 // Highlight in the middle
225 var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']);
226 menuItem.highlight("ren");
227 expect(menuItem.element().innerHTML).toEqual("Co<mark>reN</mark>LP");
228
229 menuItem.lowlight();
230 expect(menuItem.element().innerHTML).toEqual("CoreNLP");
231
232 var plain = "<div><h1>CoreNLP</h1><h2>corenlp/</h2></div>";
233
234 // Starting highlight
235 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
236 menuItem.highlight("cor");
237 expect(menuItem.element().innerHTML).toEqual("<div><h1><mark>Cor</mark>eNLP</h1><h2><mark>cor</mark>enlp/</h2></div>");
238
239 menuItem.lowlight();
240 expect(menuItem.element().innerHTML).toEqual(plain);
241
242 // Starting highlight - short
243 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
244 menuItem.highlight("c");
245 expect(menuItem.element().innerHTML).toEqual("<div><h1><mark>C</mark>oreNLP</h1><h2><mark>c</mark>orenlp/</h2></div>");
246
247 menuItem.lowlight();
248 expect(menuItem.element().innerHTML).toEqual(plain);
249
250 // Highlight at the end
251 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
252 menuItem.highlight("nlp");
253 expect(menuItem.element().innerHTML).toEqual("<div><h1>Core<mark>NLP</mark></h1><h2>core<mark>nlp</mark>/</h2></div>");
254
255 menuItem.lowlight();
256 expect(menuItem.element().innerHTML).toEqual(plain);
257
258 // Highlight at the end - short
259 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
260 menuItem.highlight("p");
261 expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNL<mark>P</mark></h1><h2>corenl<mark>p</mark>/</h2></div>");
262
263 menuItem.lowlight();
264 expect(menuItem.element().innerHTML).toEqual(plain);
265
266 // No highlight
267 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']);
268 menuItem.highlight("xp");
269 expect(menuItem.element().innerHTML).toEqual(plain);
270
271 menuItem.lowlight();
272 expect(menuItem.element().innerHTML).toEqual(plain);
273
274 // Highlight in the middle - first
275 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
276 menuItem.highlight("ren");
277 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>");
278
279 plain = "<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Example</h3></div>"
280
281 menuItem.lowlight();
282 expect(menuItem.element().innerHTML).toEqual(plain);
283
284 // Highlight in the middle - second
285 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
286 menuItem.highlight("ampl");
287 expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Ex<mark>ampl</mark>e</h3></div>");
288
289 menuItem.lowlight();
290 expect(menuItem.element().innerHTML).toEqual(plain);
291
292 // Highlight in the middle - both
293 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
294 menuItem.highlight("e");
295 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>");
296
297 menuItem.lowlight();
298 expect(menuItem.element().innerHTML).toEqual(plain);
299
300 // Highlight in the end - second
301 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
302 menuItem.highlight("le");
303 expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Examp<mark>le</mark></h3></div>");
304
305 menuItem.lowlight();
306 expect(menuItem.element().innerHTML).toEqual(plain);
307
308 // Highlight at the beginning - second
309 menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']);
310 menuItem.highlight("this");
311 expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3><mark>This</mark> is my Example</h3></div>");
312
313 menuItem.lowlight();
314 expect(menuItem.element().innerHTML).toEqual(plain);
315 });
Nils Diewaldfda29d92015-01-22 17:28:01 +0000316});
317
318
319describe('KorAP.Menu', function () {
Nils Diewald2fe12e12015-03-06 16:47:06 +0000320 var list = [
321 ["Constituency", "c=", "Example 1"],
322 ["Lemma", "l="],
323 ["Morphology", "m=", "Example 2"],
324 ["Part-of-Speech", "p="],
325 ["Syntax", "syn="]
326 ];
327
Nils Diewald5975d702015-03-09 17:45:42 +0000328 var demolist = [
329 ['Titel', 'title'],
330 ['Untertitel', 'subTitle'],
331 ['Veröffentlichungsdatum', 'pubDate'],
332 ['Länge', 'length'],
333 ['Autor', 'author']
334 ];
335
Nils Diewalde8518f82015-03-18 22:41:49 +0000336 var demolonglist = [
337 ['Titel', 'title'],
338 ['Untertitel', 'subTitle'],
339 ['Veröffentlichungsdatum', 'pubDate'],
340 ['Länge', 'length'],
341 ['Autor', 'author'],
342 ['Genre', 'genre'],
343 ['corpusID', 'corpusID'],
344 ['docID', 'docID'],
345 ['textID', 'textID'],
346 ];
347
Nils Diewaldfda29d92015-01-22 17:28:01 +0000348 it('should be initializable', function () {
Nils Diewald86dad5b2015-01-28 15:09:07 +0000349 var list = [
350 ["Constituency"],
351 ["Lemma"],
352 ["Morphology"],
353 ["Part-of-Speech"],
354 ["Syntax"]
355 ];
Nils Diewaldfda29d92015-01-22 17:28:01 +0000356
Nils Diewald86dad5b2015-01-28 15:09:07 +0000357 var menu = KorAP.OwnMenu.create(list);
358 expect(menu.itemClass()).toEqual(KorAP.OwnMenuItem);
359 expect(menu.element().nodeName).toEqual('UL');
360 expect(menu.element().style.opacity).toEqual("0");
361 expect(menu.limit()).toEqual(8);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000362
Nils Diewald86dad5b2015-01-28 15:09:07 +0000363 menu.limit(9);
364 expect(menu.limit()).toEqual(9);
365
366 menu.limit(8);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000367
368 // view
369 menu.show();
370
371 // First element in list
372 expect(menu.item(0).active()).toBe(true);
373 expect(menu.item(0).noMore()).toBe(true);
Nils Diewald86dad5b2015-01-28 15:09:07 +0000374
Nils Diewaldfda29d92015-01-22 17:28:01 +0000375 // Middle element in list
376 expect(menu.item(2).active()).toBe(false);
377 expect(menu.item(2).noMore()).toBe(false);
378
379 // Last element in list
Nils Diewald86dad5b2015-01-28 15:09:07 +0000380 expect(menu.item(menu.length() - 1).active()).toBe(false);
381 expect(menu.item(menu.length() - 1).noMore()).toBe(true);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000382 });
383
Nils Diewald6e43ffd2015-03-25 18:55:39 +0000384 it('should have a reference to the menu', function () {
385 var menu = KorAP.HintMenu.create("cnx/", list);
386 expect(menu.item(0).menu()).toEqual(menu);
387
388 menu = KorAP.HintMenu.create("cnx/", list);
389 expect(menu.element().menu).toEqual(menu);
390 });
391
392
Nils Diewaldfda29d92015-01-22 17:28:01 +0000393 it('should be visible', function () {
Nils Diewald86dad5b2015-01-28 15:09:07 +0000394 var menu = KorAP.HintMenu.create("cnx/", list);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000395 expect(menu.delete()).toBe(undefined);
Nils Diewald86dad5b2015-01-28 15:09:07 +0000396 menu.limit(3);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000397
Nils Diewald59c02fc2015-03-07 01:29:09 +0000398 expect(menu.show()).toBe(true);
Nils Diewald86dad5b2015-01-28 15:09:07 +0000399
Nils Diewald5975d702015-03-09 17:45:42 +0000400 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
401 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
402 expect(menu.element().childNodes[2].getAttribute("data-action")).toEqual("l=");
403 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
404 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000405
406 // Check boundaries
Nils Diewald5975d702015-03-09 17:45:42 +0000407 expect(menu.element().childNodes[1].classList.contains("no-more")).toBe(true);
Nils Diewald86dad5b2015-01-28 15:09:07 +0000408 expect(menu.element().childNodes[2].classList.contains("no-more")).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000409 expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(false);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000410 });
411
Nils Diewaldfda29d92015-01-22 17:28:01 +0000412 it('should be filterable', function () {
Nils Diewald86dad5b2015-01-28 15:09:07 +0000413 var menu = KorAP.HintMenu.create("cnx/", list);
414 menu.limit(3);
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].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
420 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000421
422 // Check boundaries
Nils Diewald5975d702015-03-09 17:45:42 +0000423 expect(menu.element().childNodes[1].classList.contains("no-more")).toBe(true);
424 expect(menu.element().childNodes[2].classList.contains("no-more")).toBe(false);
425 expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(true);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000426
Nils Diewald86dad5b2015-01-28 15:09:07 +0000427 menu.limit(2);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000428
Nils Diewald5975d702015-03-09 17:45:42 +0000429 expect(menu.prefix("o").show()).toBe(true);
430 expect(menu.element().childNodes[0].innerHTML).toEqual("o");
431 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
432 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>");
433 expect(menu.element().childNodes[3]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000434
435 // Check boundaries
Nils Diewald5975d702015-03-09 17:45:42 +0000436 expect(menu.element().childNodes[1].classList.contains("no-more")).toBe(true);
437 expect(menu.element().childNodes[2].classList.contains("no-more")).toBe(false);
438 expect(menu.element().childNodes[3]).toBe(undefined);
Nils Diewald86dad5b2015-01-28 15:09:07 +0000439
Nils Diewald5975d702015-03-09 17:45:42 +0000440 expect(menu.prefix("e").show()).toBe(true);
441 expect(menu.element().childNodes[0].innerHTML).toEqual("e");
442 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
443 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
444 expect(menu.element().childNodes[3]).toBe(undefined);
Nils Diewald86dad5b2015-01-28 15:09:07 +0000445
446 menu.limit(5);
Nils Diewald5975d702015-03-09 17:45:42 +0000447 expect(menu.prefix("a").show()).toBe(true);
448 expect(menu.element().childNodes[0].innerHTML).toEqual("a");
449 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Ex<mark>a</mark>mple 1</span>");
450 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemm<mark>a</mark></strong>");
451 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Ex<mark>a</mark>mple 2</span>");
452 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>P<mark>a</mark>rt-of-Speech</strong>");
453 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Synt<mark>a</mark>x</strong>");
454 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000455 });
456
Nils Diewald86dad5b2015-01-28 15:09:07 +0000457
Nils Diewaldfda29d92015-01-22 17:28:01 +0000458 it('should be nextable', function () {
Nils Diewald86dad5b2015-01-28 15:09:07 +0000459 var menu = KorAP.HintMenu.create("cnx/", list);
460
461 // Show only 3 items
462 menu.limit(3);
Nils Diewald59c02fc2015-03-07 01:29:09 +0000463 expect(menu.show()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000464 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000465 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000466 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000467 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000468 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000469 expect(menu.shownItem(2).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000470 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000471
472 // Activate next (1)
473 menu.next();
Nils Diewald5975d702015-03-09 17:45:42 +0000474 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000475 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000476 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000477 expect(menu.shownItem(1).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000478 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000479 expect(menu.shownItem(2).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000480 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000481
482 // Activate next (2)
483 menu.next();
Nils Diewald5975d702015-03-09 17:45:42 +0000484 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000485 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000486 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000487 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000488 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000489 expect(menu.shownItem(2).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000490 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000491
492 // Activate next (3)
Nils Diewald2fe12e12015-03-06 16:47:06 +0000493 // scroll!
Nils Diewaldfda29d92015-01-22 17:28:01 +0000494 menu.next();
Nils Diewald5975d702015-03-09 17:45:42 +0000495 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000496 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000497 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000498 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000499 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000500 expect(menu.shownItem(2).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000501 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000502
503 // Activate next (4)
504 menu.next();
Nils Diewald5975d702015-03-09 17:45:42 +0000505 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000506 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000507 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000508 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000509 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Syntax</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000510 expect(menu.shownItem(2).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000511 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000512
513 // Activate next (5) - ROLL
514 menu.next();
Nils Diewald5975d702015-03-09 17:45:42 +0000515 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000516 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000517 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000518 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000519 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000520 expect(menu.shownItem(2).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000521 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000522
523 // Active next (6)
524 menu.next();
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(false);
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(true);
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
Nils Diewaldfda29d92015-01-22 17:28:01 +0000534 it('should be prevable', function () {
Nils Diewald2fe12e12015-03-06 16:47:06 +0000535 var menu = KorAP.HintMenu.create("cnx/", list);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000536 menu.limit(3);
Nils Diewald59c02fc2015-03-07 01:29:09 +0000537 expect(menu.show()).toBe(true);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000538
Nils Diewald5975d702015-03-09 17:45:42 +0000539 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000540 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000541 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000542 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000543 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000544 expect(menu.shownItem(2).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000545 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000546
547 // Activate prev (1) - roll to bottom
548 menu.prev();
Nils Diewald5975d702015-03-09 17:45:42 +0000549 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000550 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000551 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000552 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000553 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Syntax</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000554 expect(menu.shownItem(2).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000555 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000556
557 // Activate prev (2)
558 menu.prev();
Nils Diewald5975d702015-03-09 17:45:42 +0000559 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000560 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000561 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000562 expect(menu.shownItem(1).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000563 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Syntax</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000564 expect(menu.shownItem(2).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000565 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000566
567 // Activate prev (3)
568 menu.prev();
Nils Diewald2fe12e12015-03-06 16:47:06 +0000569 expect(menu.shownItem(0).name()).toEqual("Morphology");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000570 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000571 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000572 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000573 expect(menu.shownItem(2).name()).toEqual("Syntax");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000574 expect(menu.shownItem(2).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000575 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000576
577 // Activate prev (4)
578 menu.prev();
Nils Diewald2fe12e12015-03-06 16:47:06 +0000579 expect(menu.shownItem(0).name()).toEqual("Lemma");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000580 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000581 expect(menu.shownItem(1).name()).toEqual("Morphology");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000582 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000583 expect(menu.shownItem(2).name()).toEqual("Part-of-Speech");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000584 expect(menu.shownItem(2).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000585 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000586
587 // Activate prev (5)
588 menu.prev();
Nils Diewald2fe12e12015-03-06 16:47:06 +0000589 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000590 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000591 expect(menu.shownItem(1).name()).toEqual("Lemma");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000592 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000593 expect(menu.shownItem(2).name()).toEqual("Morphology");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000594 expect(menu.shownItem(2).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000595 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000596
597 // Activate next (1)
598 menu.next();
Nils Diewald2fe12e12015-03-06 16:47:06 +0000599 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000600 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000601 expect(menu.shownItem(1).name()).toEqual("Lemma");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000602 expect(menu.shownItem(1).active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000603 expect(menu.shownItem(2).name()).toEqual("Morphology");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000604 expect(menu.shownItem(2).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000605 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000606
607 // Activate prev (6)
608 menu.prev();
609
610 // Activate prev (7)
611 menu.prev();
Nils Diewald2fe12e12015-03-06 16:47:06 +0000612 expect(menu.shownItem(0).name()).toEqual("Morphology");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000613 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000614 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000615 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000616 expect(menu.shownItem(2).name()).toEqual("Syntax");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000617 expect(menu.shownItem(2).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000618 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000619 });
620
Nils Diewaldfda29d92015-01-22 17:28:01 +0000621
Nils Diewald2fe12e12015-03-06 16:47:06 +0000622 it('should be navigatable and filterable (prefix = "o")', function () {
623 var menu = KorAP.HintMenu.create("cnx/", list);
624 menu.limit(2);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000625
Nils Diewald5975d702015-03-09 17:45:42 +0000626 expect(menu.prefix("o").show()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000627 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewald5975d702015-03-09 17:45:42 +0000628 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 +0000629 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000630 expect(menu.shownItem(1).name()).toEqual("Morphology");
Nils Diewald5975d702015-03-09 17:45:42 +0000631 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 +0000632 expect(menu.shownItem(1).active()).toBe(false);
633 expect(menu.shownItem(2)).toBe(undefined);
634
635 // Next (1)
636 menu.next();
Nils Diewald2fe12e12015-03-06 16:47:06 +0000637 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewald5975d702015-03-09 17:45:42 +0000638 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 +0000639 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000640 expect(menu.shownItem(1).name()).toEqual("Morphology");
Nils Diewald5975d702015-03-09 17:45:42 +0000641 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 +0000642 expect(menu.shownItem(1).active()).toBe(true);
643 expect(menu.shownItem(2)).toBe(undefined);
644
Nils Diewaldfda29d92015-01-22 17:28:01 +0000645 // Next (2)
646 menu.next();
Nils Diewald2fe12e12015-03-06 16:47:06 +0000647 expect(menu.shownItem(0).name()).toEqual("Morphology");
Nils Diewald5975d702015-03-09 17:45:42 +0000648 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 +0000649 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000650 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
Nils Diewald5975d702015-03-09 17:45:42 +0000651 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000652 expect(menu.shownItem(1).active()).toBe(true);
653 expect(menu.shownItem(2)).toBe(undefined);
654
Nils Diewald5975d702015-03-09 17:45:42 +0000655 // Next (3) - to prefix
656 menu.next();
657 expect(menu.shownItem(0).name()).toEqual("Morphology");
658 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>");
659 expect(menu.shownItem(0).active()).toBe(false);
660 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
661 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
662 expect(menu.shownItem(1).active()).toBe(false);
663 expect(menu.shownItem(2)).toBe(undefined);
664
Nils Diewaldfda29d92015-01-22 17:28:01 +0000665 menu.next();
Nils Diewald2fe12e12015-03-06 16:47:06 +0000666 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewald5975d702015-03-09 17:45:42 +0000667 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 +0000668 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000669 expect(menu.shownItem(1).name()).toEqual("Morphology");
Nils Diewald5975d702015-03-09 17:45:42 +0000670 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 +0000671 expect(menu.shownItem(1).active()).toBe(false);
672 expect(menu.shownItem(2)).toBe(undefined);
673 });
674
Nils Diewald2fe12e12015-03-06 16:47:06 +0000675
Nils Diewaldfda29d92015-01-22 17:28:01 +0000676 it('should be navigatable and filterable (prefix = "ex", "e")', function () {
Nils Diewald2fe12e12015-03-06 16:47:06 +0000677 var menu = KorAP.HintMenu.create("cnx/", list);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000678
Nils Diewald2fe12e12015-03-06 16:47:06 +0000679 menu.limit(2);
Nils Diewald5975d702015-03-09 17:45:42 +0000680 expect(menu.prefix("ex").show()).toBe(true);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000681
Nils Diewald2fe12e12015-03-06 16:47:06 +0000682 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewald5975d702015-03-09 17:45:42 +0000683 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000684 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000685 expect(menu.shownItem(1).name()).toEqual("Morphology");
Nils Diewald5975d702015-03-09 17:45:42 +0000686 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000687 expect(menu.shownItem(1).active()).toBe(false);
688 expect(menu.shownItem(2)).toBe(undefined);
689
690 // Next (1)
691 menu.next();
Nils Diewald2fe12e12015-03-06 16:47:06 +0000692 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewald5975d702015-03-09 17:45:42 +0000693 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000694 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000695 expect(menu.shownItem(1).name()).toEqual("Morphology");
Nils Diewald5975d702015-03-09 17:45:42 +0000696 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000697 expect(menu.shownItem(1).active()).toBe(true);
698 expect(menu.shownItem(2)).toBe(undefined);
699
700 // Next (2)
701 menu.next();
Nils Diewald5975d702015-03-09 17:45:42 +0000702
703 expect(menu.prefix()).toEqual('ex');
Nils Diewald2fe12e12015-03-06 16:47:06 +0000704 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewald5975d702015-03-09 17:45:42 +0000705 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
706 expect(menu.shownItem(0).active()).toBe(false);
707
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>Ex</mark>ample 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 // Reset limit
Nils Diewald2fe12e12015-03-06 16:47:06 +0000714 menu.limit(5);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000715
716 // Change show
Nils Diewald5975d702015-03-09 17:45:42 +0000717 expect(menu.prefix("e").show()).toBe(true);
Nils Diewalde8518f82015-03-18 22:41:49 +0000718 expect(menu._prefix.active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000719 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewald5975d702015-03-09 17:45:42 +0000720 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 +0000721 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000722 expect(menu.shownItem(1).name()).toEqual("Morphology");
Nils Diewald5975d702015-03-09 17:45:42 +0000723 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 +0000724 expect(menu.shownItem(1).active()).toBe(false);
725 expect(menu.shownItem(2)).toBe(undefined);
726
727 // Next (1)
728 menu.next();
Nils Diewald5975d702015-03-09 17:45:42 +0000729 expect(menu._prefix.active()).toBe(false);
730 expect(menu.prefix()).toEqual('e');
Nils Diewald2fe12e12015-03-06 16:47:06 +0000731 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewald5975d702015-03-09 17:45:42 +0000732 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 +0000733 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000734 expect(menu.shownItem(1).name()).toEqual("Morphology");
Nils Diewald5975d702015-03-09 17:45:42 +0000735 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 +0000736 expect(menu.shownItem(1).active()).toBe(true);
737 expect(menu.shownItem(2)).toBe(undefined);
738
739 // Next (2)
740 menu.next();
Nils Diewald5975d702015-03-09 17:45:42 +0000741 expect(menu._prefix.active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000742 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewald5975d702015-03-09 17:45:42 +0000743 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
744 expect(menu.shownItem(0).active()).toBe(false);
745 expect(menu.shownItem(1).name()).toEqual("Morphology");
746 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
747 expect(menu.shownItem(1).active()).toBe(false);
748 expect(menu.shownItem(2)).toBe(undefined);
749
750 // Next (3)
751 menu.next();
752 expect(menu._prefix.active()).toBe(false);
753 expect(menu.shownItem(0).name()).toEqual("Constituency");
754 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 +0000755 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000756 expect(menu.shownItem(1).name()).toEqual("Morphology");
Nils Diewald5975d702015-03-09 17:45:42 +0000757 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 +0000758 expect(menu.shownItem(1).active()).toBe(false);
759 expect(menu.shownItem(2)).toBe(undefined);
760 });
Nils Diewald5975d702015-03-09 17:45:42 +0000761
762
763 it('shouldn\'t be viewable with failing prefix', function () {
764 var menu = KorAP.HintMenu.create("cnx/", list);
765 menu.limit(2);
766 expect(menu.prefix("exit").show()).toBe(false);
767 });
768
769 it('should be navigatable with prefix', function () {
770 var menu = KorAP.HintMenu.create("cnx/", demolist);
771 menu.limit(3);
772
773 expect(menu.show()).toBe(true);
774 expect(menu.prefix()).toEqual("");
775
776 expect(menu.shownItem(0).name()).toEqual("Titel");
777 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
778 expect(menu.shownItem(0).active()).toBe(true);
779 expect(menu.shownItem(1).name()).toEqual("Untertitel");
780 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
781 expect(menu.shownItem(1).active()).toBe(false);
782 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
783 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
784 expect(menu.shownItem(2).active()).toBe(false);
785 expect(menu.shownItem(3)).toBe(undefined);
786
787 menu._prefix.add('a');
788 expect(menu.show()).toBe(true);
789 expect(menu.prefix()).toEqual("a");
790 expect(menu.shownItem(0).name()).toEqual("Autor");
791 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
792
793 menu._prefix.add('u');
794 expect(menu.show()).toBe(true);
795 expect(menu.prefix()).toEqual("au");
796 expect(menu.shownItem(0).name()).toEqual("Autor");
797 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong><mark>Au</mark>tor</strong>");
798
799 menu._prefix.backspace();
800 expect(menu.show()).toBe(true);
801 expect(menu.prefix()).toEqual("a");
802 expect(menu.shownItem(0).name()).toEqual("Autor");
803 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
804
805 menu._prefix.backspace();
806 expect(menu.show()).toBe(true);
807 expect(menu.prefix()).toEqual("");
808 expect(menu.shownItem(0).name()).toEqual("Titel");
809 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
810 expect(menu.shownItem(0).active()).toBe(true);
811 expect(menu.shownItem(1).name()).toEqual("Untertitel");
812 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
813 expect(menu.shownItem(1).active()).toBe(false);
814 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
815 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
816 expect(menu.shownItem(2).active()).toBe(false);
817 expect(menu.shownItem(3)).toBe(undefined);
818
819 // Forward
820 menu._prefix.backspace();
821 expect(menu.show()).toBe(true);
822 expect(menu.prefix()).toEqual("");
823 expect(menu.shownItem(0).name()).toEqual("Titel");
824 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
825 expect(menu.shownItem(0).active()).toBe(true);
826 expect(menu.shownItem(1).name()).toEqual("Untertitel");
827 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
828 expect(menu.shownItem(1).active()).toBe(false);
829 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
830 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
831 expect(menu.shownItem(2).active()).toBe(false);
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(true);
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(false);
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("Titel");
851 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
852 expect(menu.shownItem(0).active()).toBe(false);
853 expect(menu.shownItem(1).name()).toEqual("Untertitel");
854 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
855 expect(menu.shownItem(1).active()).toBe(false);
856 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
857 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</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("Untertitel");
865 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Untertitel</strong>");
866 expect(menu.shownItem(0).active()).toBe(false);
867 expect(menu.shownItem(1).name()).toEqual("Veröffentlichungsdatum");
868 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
869 expect(menu.shownItem(1).active()).toBe(false);
870 expect(menu.shownItem(2).name()).toEqual("Länge");
871 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Länge</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("Veröffentlichungsdatum");
879 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
880 expect(menu.shownItem(0).active()).toBe(false);
881 expect(menu.shownItem(1).name()).toEqual("Länge");
882 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Länge</strong>");
883 expect(menu.shownItem(1).active()).toBe(false);
884 expect(menu.shownItem(2).name()).toEqual("Autor");
885 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Autor</strong>");
886 expect(menu.shownItem(2).active()).toBe(true);
887 expect(menu.shownItem(3)).toBe(undefined);
888
889 // Forward
890 menu.next();
891 expect(menu.prefix()).toEqual("");
892 expect(menu.shownItem(0).name()).toEqual("Titel");
893 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
894 expect(menu.shownItem(0).active()).toBe(true);
895 expect(menu.shownItem(1).name()).toEqual("Untertitel");
896 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
897 expect(menu.shownItem(1).active()).toBe(false);
898 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
899 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
900 expect(menu.shownItem(2).active()).toBe(false);
901
902 });
903
904
905 it('should be navigatable with a prefix (1)', function () {
906 var menu = KorAP.HintMenu.create("cnx/", demolist);
907 menu.limit(3);
908
909 expect(menu.show()).toBe(true);
910 expect(menu.prefix()).toEqual("");
911
912 menu.prefix('el');
913 expect(menu.show()).toBe(true);
914
915 expect(menu.prefix()).toEqual("el");
916 expect(menu._prefix.active()).toEqual(false);
917 expect(menu.shownItem(0).name()).toEqual("Titel");
918 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
919 expect(menu.shownItem(0).active()).toBe(true);
920 expect(menu.shownItem(1).name()).toEqual("Untertitel");
921 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
922 expect(menu.shownItem(1).active()).toBe(false);
923 expect(menu.shownItem(2)).toBe(undefined);
924
925 // Forward
926 menu.next();
927 expect(menu.prefix()).toEqual("el");
928 expect(menu._prefix.active()).toEqual(false);
929 expect(menu.shownItem(0).name()).toEqual("Titel");
930 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
931 expect(menu.shownItem(0).active()).toBe(false);
932 expect(menu.shownItem(1).name()).toEqual("Untertitel");
933 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
934 expect(menu.shownItem(1).active()).toBe(true);
935 expect(menu.shownItem(2)).toBe(undefined);
936
937 // Forward
938 menu.next();
939 expect(menu.prefix()).toEqual("el");
940 expect(menu._prefix.active()).toEqual(true);
941 expect(menu.shownItem(0).name()).toEqual("Titel");
942 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
943 expect(menu.shownItem(0).active()).toBe(false);
944 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(false);
947 expect(menu.shownItem(2)).toBe(undefined);
948
949
950 // Backward
951 menu.prev();
952 expect(menu.prefix()).toEqual("el");
953 expect(menu._prefix.active()).toEqual(false);
954 expect(menu.shownItem(0).name()).toEqual("Titel");
955 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
956 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald2d210752015-03-09 19:01:15 +0000957
Nils Diewald5975d702015-03-09 17:45:42 +0000958 expect(menu.shownItem(1).name()).toEqual("Untertitel");
959 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
960 expect(menu.shownItem(1).active()).toBe(true);
961 expect(menu.shownItem(2)).toBe(undefined);
962 });
963
Nils Diewalde8518f82015-03-18 22:41:49 +0000964
Nils Diewald2d210752015-03-09 19:01:15 +0000965 it('should be navigatable with a prefix (2)', function () {
Nils Diewald5975d702015-03-09 17:45:42 +0000966 var menu = KorAP.HintMenu.create("cnx/", demolist);
967 menu.limit(3);
968 expect(menu.show()).toBe(true);
969 expect(menu.prefix()).toEqual("");
970 menu.prefix('el');
971 expect(menu.show()).toBe(true);
972
973 expect(menu.prefix()).toEqual("el");
974 expect(menu._prefix.active()).toEqual(false);
975 expect(menu.shownItem(0).name()).toEqual("Titel");
976 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
977 expect(menu.shownItem(0).active()).toBe(true);
978 expect(menu.shownItem(1).name()).toEqual("Untertitel");
979 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
980 expect(menu.shownItem(1).active()).toBe(false);
981 expect(menu.shownItem(2)).toBe(undefined);
982
983 // Backward
984 menu.prev();
985 expect(menu._prefix.active()).toEqual(true);
Nils Diewald2d210752015-03-09 19:01:15 +0000986
Nils Diewald5975d702015-03-09 17:45:42 +0000987 expect(menu.shownItem(0).name()).toEqual("Titel");
988 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
989 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald2d210752015-03-09 19:01:15 +0000990
Nils Diewald5975d702015-03-09 17:45:42 +0000991 expect(menu.shownItem(1).name()).toEqual("Untertitel");
992 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
993 expect(menu.shownItem(1).active()).toBe(false);
994 expect(menu.shownItem(2)).toBe(undefined);
995
996 // Backward
Nils Diewald5975d702015-03-09 17:45:42 +0000997 menu.prev();
998 expect(menu._prefix.active()).toEqual(false);
999 expect(menu.shownItem(0).name()).toEqual("Titel");
1000 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1001 expect(menu.shownItem(0).active()).toBe(false);
1002 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1003 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1004 expect(menu.shownItem(1).active()).toBe(true);
1005 expect(menu.shownItem(2)).toBe(undefined);
Nils Diewald5975d702015-03-09 17:45:42 +00001006 });
1007
Nils Diewalde8518f82015-03-18 22:41:49 +00001008 it('should be navigatable with a prefix (3)', function () {
1009 var menu = KorAP.HintMenu.create("cnx/", demolist);
1010 menu.limit(3);
1011 expect(menu.show()).toBe(true);
1012 expect(menu.prefix()).toEqual("");
1013 menu.prefix('el');
1014 expect(menu.show()).toBe(true);
1015
1016 expect(menu.prefix()).toEqual("el");
1017 expect(menu._prefix.active()).toEqual(false);
1018 expect(menu.shownItem(0).name()).toEqual("Titel");
1019 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1020 expect(menu.shownItem(0).active()).toBe(true);
1021 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1022 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1023 expect(menu.shownItem(1).active()).toBe(false);
1024 expect(menu.shownItem(2)).toBe(undefined);
1025
1026 // Backward
1027 menu.prev();
1028 expect(menu._prefix.active()).toEqual(true);
1029 expect(menu.shownItem(0).name()).toEqual("Titel");
1030 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1031 expect(menu.shownItem(0).active()).toBe(false);
1032 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1033 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1034 expect(menu.shownItem(1).active()).toBe(false);
1035 expect(menu.shownItem(2)).toBe(undefined);
1036
1037
1038 // Forward
1039 menu.next();
1040 expect(menu.prefix()).toEqual("el");
1041 expect(menu._prefix.active()).toEqual(false);
1042 expect(menu.shownItem(0).name()).toEqual("Titel");
1043 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
1044 expect(menu.shownItem(0).active()).toBe(true);
1045 expect(menu.shownItem(1).name()).toEqual("Untertitel");
1046 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
1047 expect(menu.shownItem(1).active()).toBe(false);
1048 expect(menu.shownItem(2)).toBe(undefined);
1049
1050 });
1051
Nils Diewald6e43ffd2015-03-25 18:55:39 +00001052 xit('should be page downable');
Nils Diewald5975d702015-03-09 17:45:42 +00001053 xit('should be page upable');
Nils Diewalda297f062015-04-02 00:23:46 +00001054
1055 xit('should scroll to a chosen value')
1056 xit('should highlight a chosen value')
Nils Diewaldfda29d92015-01-22 17:28:01 +00001057});