blob: a8185742c6883f914898f9d1d3adabc550086f28 [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 Diewaldfda29d92015-01-22 17:28:01 +0000331 it('should be initializable', function () {
Nils Diewald86dad5b2015-01-28 15:09:07 +0000332 var list = [
333 ["Constituency"],
334 ["Lemma"],
335 ["Morphology"],
336 ["Part-of-Speech"],
337 ["Syntax"]
338 ];
Nils Diewaldfda29d92015-01-22 17:28:01 +0000339
Nils Diewald86dad5b2015-01-28 15:09:07 +0000340 var menu = KorAP.OwnMenu.create(list);
341 expect(menu.itemClass()).toEqual(KorAP.OwnMenuItem);
342 expect(menu.element().nodeName).toEqual('UL');
343 expect(menu.element().style.opacity).toEqual("0");
344 expect(menu.limit()).toEqual(8);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000345
Nils Diewald86dad5b2015-01-28 15:09:07 +0000346 menu.limit(9);
347 expect(menu.limit()).toEqual(9);
348
349 menu.limit(8);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000350
351 // view
352 menu.show();
353
354 // First element in list
355 expect(menu.item(0).active()).toBe(true);
356 expect(menu.item(0).noMore()).toBe(true);
Nils Diewald86dad5b2015-01-28 15:09:07 +0000357
Nils Diewaldfda29d92015-01-22 17:28:01 +0000358 // Middle element in list
359 expect(menu.item(2).active()).toBe(false);
360 expect(menu.item(2).noMore()).toBe(false);
361
362 // Last element in list
Nils Diewald86dad5b2015-01-28 15:09:07 +0000363 expect(menu.item(menu.length() - 1).active()).toBe(false);
364 expect(menu.item(menu.length() - 1).noMore()).toBe(true);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000365 });
366
367 it('should be visible', function () {
Nils Diewald86dad5b2015-01-28 15:09:07 +0000368 var menu = KorAP.HintMenu.create("cnx/", list);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000369 expect(menu.delete()).toBe(undefined);
Nils Diewald86dad5b2015-01-28 15:09:07 +0000370 menu.limit(3);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000371
Nils Diewald59c02fc2015-03-07 01:29:09 +0000372 expect(menu.show()).toBe(true);
Nils Diewald86dad5b2015-01-28 15:09:07 +0000373
Nils Diewald5975d702015-03-09 17:45:42 +0000374 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
375 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
376 expect(menu.element().childNodes[2].getAttribute("data-action")).toEqual("l=");
377 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
378 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000379
380 // Check boundaries
Nils Diewald5975d702015-03-09 17:45:42 +0000381 expect(menu.element().childNodes[1].classList.contains("no-more")).toBe(true);
Nils Diewald86dad5b2015-01-28 15:09:07 +0000382 expect(menu.element().childNodes[2].classList.contains("no-more")).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000383 expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(false);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000384 });
385
Nils Diewaldfda29d92015-01-22 17:28:01 +0000386 it('should be filterable', function () {
Nils Diewald86dad5b2015-01-28 15:09:07 +0000387 var menu = KorAP.HintMenu.create("cnx/", list);
388 menu.limit(3);
Nils Diewald5975d702015-03-09 17:45:42 +0000389 expect(menu.prefix("o").show()).toBe(true);
390 expect(menu.element().childNodes[0].innerHTML).toEqual("o");
391 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
392 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>");
393 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
394 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000395
396 // Check boundaries
Nils Diewald5975d702015-03-09 17:45:42 +0000397 expect(menu.element().childNodes[1].classList.contains("no-more")).toBe(true);
398 expect(menu.element().childNodes[2].classList.contains("no-more")).toBe(false);
399 expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(true);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000400
Nils Diewald86dad5b2015-01-28 15:09:07 +0000401 menu.limit(2);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000402
Nils Diewald5975d702015-03-09 17:45:42 +0000403 expect(menu.prefix("o").show()).toBe(true);
404 expect(menu.element().childNodes[0].innerHTML).toEqual("o");
405 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
406 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>");
407 expect(menu.element().childNodes[3]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000408
409 // Check boundaries
Nils Diewald5975d702015-03-09 17:45:42 +0000410 expect(menu.element().childNodes[1].classList.contains("no-more")).toBe(true);
411 expect(menu.element().childNodes[2].classList.contains("no-more")).toBe(false);
412 expect(menu.element().childNodes[3]).toBe(undefined);
Nils Diewald86dad5b2015-01-28 15:09:07 +0000413
Nils Diewald5975d702015-03-09 17:45:42 +0000414 expect(menu.prefix("e").show()).toBe(true);
415 expect(menu.element().childNodes[0].innerHTML).toEqual("e");
416 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
417 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
418 expect(menu.element().childNodes[3]).toBe(undefined);
Nils Diewald86dad5b2015-01-28 15:09:07 +0000419
420 menu.limit(5);
Nils Diewald5975d702015-03-09 17:45:42 +0000421 expect(menu.prefix("a").show()).toBe(true);
422 expect(menu.element().childNodes[0].innerHTML).toEqual("a");
423 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Ex<mark>a</mark>mple 1</span>");
424 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemm<mark>a</mark></strong>");
425 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Ex<mark>a</mark>mple 2</span>");
426 expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>P<mark>a</mark>rt-of-Speech</strong>");
427 expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Synt<mark>a</mark>x</strong>");
428 expect(menu.element().childNodes[6]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000429 });
430
Nils Diewald86dad5b2015-01-28 15:09:07 +0000431
Nils Diewaldfda29d92015-01-22 17:28:01 +0000432 it('should be nextable', function () {
Nils Diewald86dad5b2015-01-28 15:09:07 +0000433 var menu = KorAP.HintMenu.create("cnx/", list);
434
435 // Show only 3 items
436 menu.limit(3);
Nils Diewald59c02fc2015-03-07 01:29:09 +0000437 expect(menu.show()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000438 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000439 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000440 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000441 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000442 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000443 expect(menu.shownItem(2).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000444 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000445
446 // Activate next (1)
447 menu.next();
Nils Diewald5975d702015-03-09 17:45:42 +0000448 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000449 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000450 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000451 expect(menu.shownItem(1).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000452 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000453 expect(menu.shownItem(2).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000454 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000455
456 // Activate next (2)
457 menu.next();
Nils Diewald5975d702015-03-09 17:45:42 +0000458 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000459 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000460 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000461 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000462 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000463 expect(menu.shownItem(2).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000464 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000465
466 // Activate next (3)
Nils Diewald2fe12e12015-03-06 16:47:06 +0000467 // scroll!
Nils Diewaldfda29d92015-01-22 17:28:01 +0000468 menu.next();
Nils Diewald5975d702015-03-09 17:45:42 +0000469 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000470 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000471 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000472 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000473 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000474 expect(menu.shownItem(2).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000475 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000476
477 // Activate next (4)
478 menu.next();
Nils Diewald5975d702015-03-09 17:45:42 +0000479 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000480 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000481 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000482 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000483 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Syntax</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000484 expect(menu.shownItem(2).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000485 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000486
487 // Activate next (5) - ROLL
488 menu.next();
Nils Diewald5975d702015-03-09 17:45:42 +0000489 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000490 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000491 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000492 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000493 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000494 expect(menu.shownItem(2).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000495 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000496
497 // Active next (6)
498 menu.next();
Nils Diewald5975d702015-03-09 17:45:42 +0000499 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000500 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000501 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000502 expect(menu.shownItem(1).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000503 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000504 expect(menu.shownItem(2).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000505 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000506 });
507
Nils Diewaldfda29d92015-01-22 17:28:01 +0000508 it('should be prevable', function () {
Nils Diewald2fe12e12015-03-06 16:47:06 +0000509 var menu = KorAP.HintMenu.create("cnx/", list);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000510 menu.limit(3);
Nils Diewald59c02fc2015-03-07 01:29:09 +0000511 expect(menu.show()).toBe(true);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000512
Nils Diewald5975d702015-03-09 17:45:42 +0000513 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000514 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000515 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000516 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000517 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000518 expect(menu.shownItem(2).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000519 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000520
521 // Activate prev (1) - roll to bottom
522 menu.prev();
Nils Diewald5975d702015-03-09 17:45:42 +0000523 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000524 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000525 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000526 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000527 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Syntax</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000528 expect(menu.shownItem(2).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000529 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000530
531 // Activate prev (2)
532 menu.prev();
Nils Diewald5975d702015-03-09 17:45:42 +0000533 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000534 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000535 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000536 expect(menu.shownItem(1).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000537 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Syntax</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000538 expect(menu.shownItem(2).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000539 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000540
541 // Activate prev (3)
542 menu.prev();
Nils Diewald2fe12e12015-03-06 16:47:06 +0000543 expect(menu.shownItem(0).name()).toEqual("Morphology");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000544 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000545 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000546 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000547 expect(menu.shownItem(2).name()).toEqual("Syntax");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000548 expect(menu.shownItem(2).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000549 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000550
551 // Activate prev (4)
552 menu.prev();
Nils Diewald2fe12e12015-03-06 16:47:06 +0000553 expect(menu.shownItem(0).name()).toEqual("Lemma");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000554 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000555 expect(menu.shownItem(1).name()).toEqual("Morphology");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000556 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000557 expect(menu.shownItem(2).name()).toEqual("Part-of-Speech");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000558 expect(menu.shownItem(2).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000559 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000560
561 // Activate prev (5)
562 menu.prev();
Nils Diewald2fe12e12015-03-06 16:47:06 +0000563 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000564 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000565 expect(menu.shownItem(1).name()).toEqual("Lemma");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000566 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000567 expect(menu.shownItem(2).name()).toEqual("Morphology");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000568 expect(menu.shownItem(2).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000569 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000570
571 // Activate next (1)
572 menu.next();
Nils Diewald2fe12e12015-03-06 16:47:06 +0000573 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000574 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000575 expect(menu.shownItem(1).name()).toEqual("Lemma");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000576 expect(menu.shownItem(1).active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000577 expect(menu.shownItem(2).name()).toEqual("Morphology");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000578 expect(menu.shownItem(2).active()).toBe(false);
Nils Diewald5975d702015-03-09 17:45:42 +0000579 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000580
581 // Activate prev (6)
582 menu.prev();
583
584 // Activate prev (7)
585 menu.prev();
Nils Diewald2fe12e12015-03-06 16:47:06 +0000586 expect(menu.shownItem(0).name()).toEqual("Morphology");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000587 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000588 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000589 expect(menu.shownItem(1).active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000590 expect(menu.shownItem(2).name()).toEqual("Syntax");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000591 expect(menu.shownItem(2).active()).toBe(true);
Nils Diewald5975d702015-03-09 17:45:42 +0000592 expect(menu.element().childNodes[4]).toBe(undefined);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000593 });
594
Nils Diewaldfda29d92015-01-22 17:28:01 +0000595
Nils Diewald2fe12e12015-03-06 16:47:06 +0000596 it('should be navigatable and filterable (prefix = "o")', function () {
597 var menu = KorAP.HintMenu.create("cnx/", list);
598 menu.limit(2);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000599
Nils Diewald5975d702015-03-09 17:45:42 +0000600 expect(menu.prefix("o").show()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000601 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewald5975d702015-03-09 17:45:42 +0000602 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 +0000603 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000604 expect(menu.shownItem(1).name()).toEqual("Morphology");
Nils Diewald5975d702015-03-09 17:45:42 +0000605 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 +0000606 expect(menu.shownItem(1).active()).toBe(false);
607 expect(menu.shownItem(2)).toBe(undefined);
608
609 // Next (1)
610 menu.next();
Nils Diewald2fe12e12015-03-06 16:47:06 +0000611 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewald5975d702015-03-09 17:45:42 +0000612 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 +0000613 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000614 expect(menu.shownItem(1).name()).toEqual("Morphology");
Nils Diewald5975d702015-03-09 17:45:42 +0000615 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 +0000616 expect(menu.shownItem(1).active()).toBe(true);
617 expect(menu.shownItem(2)).toBe(undefined);
618
Nils Diewaldfda29d92015-01-22 17:28:01 +0000619 // Next (2)
620 menu.next();
Nils Diewald2fe12e12015-03-06 16:47:06 +0000621 expect(menu.shownItem(0).name()).toEqual("Morphology");
Nils Diewald5975d702015-03-09 17:45:42 +0000622 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 +0000623 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000624 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
Nils Diewald5975d702015-03-09 17:45:42 +0000625 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000626 expect(menu.shownItem(1).active()).toBe(true);
627 expect(menu.shownItem(2)).toBe(undefined);
628
Nils Diewald5975d702015-03-09 17:45:42 +0000629 // Next (3) - to prefix
630 menu.next();
631 expect(menu.shownItem(0).name()).toEqual("Morphology");
632 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>");
633 expect(menu.shownItem(0).active()).toBe(false);
634 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
635 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
636 expect(menu.shownItem(1).active()).toBe(false);
637 expect(menu.shownItem(2)).toBe(undefined);
638
Nils Diewaldfda29d92015-01-22 17:28:01 +0000639 menu.next();
Nils Diewald2fe12e12015-03-06 16:47:06 +0000640 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewald5975d702015-03-09 17:45:42 +0000641 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 +0000642 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000643 expect(menu.shownItem(1).name()).toEqual("Morphology");
Nils Diewald5975d702015-03-09 17:45:42 +0000644 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 +0000645 expect(menu.shownItem(1).active()).toBe(false);
646 expect(menu.shownItem(2)).toBe(undefined);
647 });
648
Nils Diewald2fe12e12015-03-06 16:47:06 +0000649
Nils Diewaldfda29d92015-01-22 17:28:01 +0000650 it('should be navigatable and filterable (prefix = "ex", "e")', function () {
Nils Diewald2fe12e12015-03-06 16:47:06 +0000651 var menu = KorAP.HintMenu.create("cnx/", list);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000652
Nils Diewald2fe12e12015-03-06 16:47:06 +0000653 menu.limit(2);
Nils Diewald5975d702015-03-09 17:45:42 +0000654 expect(menu.prefix("ex").show()).toBe(true);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000655
Nils Diewald2fe12e12015-03-06 16:47:06 +0000656 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewald5975d702015-03-09 17:45:42 +0000657 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000658 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000659 expect(menu.shownItem(1).name()).toEqual("Morphology");
Nils Diewald5975d702015-03-09 17:45:42 +0000660 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000661 expect(menu.shownItem(1).active()).toBe(false);
662 expect(menu.shownItem(2)).toBe(undefined);
663
664 // Next (1)
665 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>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000668 expect(menu.shownItem(0).active()).toBe(false);
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>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000671 expect(menu.shownItem(1).active()).toBe(true);
672 expect(menu.shownItem(2)).toBe(undefined);
673
674 // Next (2)
675 menu.next();
Nils Diewald5975d702015-03-09 17:45:42 +0000676
677 expect(menu.prefix()).toEqual('ex');
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>");
680 expect(menu.shownItem(0).active()).toBe(false);
681
Nils Diewald2fe12e12015-03-06 16:47:06 +0000682 expect(menu.shownItem(1).name()).toEqual("Morphology");
Nils Diewald5975d702015-03-09 17:45:42 +0000683 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
Nils Diewaldfda29d92015-01-22 17:28:01 +0000684 expect(menu.shownItem(1).active()).toBe(false);
685 expect(menu.shownItem(2)).toBe(undefined);
686
687 // Reset limit
Nils Diewald2fe12e12015-03-06 16:47:06 +0000688 menu.limit(5);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000689
690 // Change show
Nils Diewald5975d702015-03-09 17:45:42 +0000691 expect(menu.prefix("e").show()).toBe(true);
Nils Diewaldfda29d92015-01-22 17:28:01 +0000692
Nils Diewald2fe12e12015-03-06 16:47:06 +0000693 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewald5975d702015-03-09 17:45:42 +0000694 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 +0000695 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000696 expect(menu.shownItem(1).name()).toEqual("Morphology");
Nils Diewald5975d702015-03-09 17:45:42 +0000697 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 +0000698 expect(menu.shownItem(1).active()).toBe(false);
699 expect(menu.shownItem(2)).toBe(undefined);
700
701 // Next (1)
702 menu.next();
Nils Diewald5975d702015-03-09 17:45:42 +0000703 expect(menu._prefix.active()).toBe(false);
704 expect(menu.prefix()).toEqual('e');
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(false);
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(true);
711 expect(menu.shownItem(2)).toBe(undefined);
712
713 // Next (2)
714 menu.next();
Nils Diewald5975d702015-03-09 17:45:42 +0000715 expect(menu._prefix.active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000716 expect(menu.shownItem(0).name()).toEqual("Constituency");
Nils Diewald5975d702015-03-09 17:45:42 +0000717 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
718 expect(menu.shownItem(0).active()).toBe(false);
719 expect(menu.shownItem(1).name()).toEqual("Morphology");
720 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
721 expect(menu.shownItem(1).active()).toBe(false);
722 expect(menu.shownItem(2)).toBe(undefined);
723
724 // Next (3)
725 menu.next();
726 expect(menu._prefix.active()).toBe(false);
727 expect(menu.shownItem(0).name()).toEqual("Constituency");
728 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 +0000729 expect(menu.shownItem(0).active()).toBe(true);
Nils Diewald2fe12e12015-03-06 16:47:06 +0000730 expect(menu.shownItem(1).name()).toEqual("Morphology");
Nils Diewald5975d702015-03-09 17:45:42 +0000731 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 +0000732 expect(menu.shownItem(1).active()).toBe(false);
733 expect(menu.shownItem(2)).toBe(undefined);
734 });
Nils Diewald5975d702015-03-09 17:45:42 +0000735
736
737 it('shouldn\'t be viewable with failing prefix', function () {
738 var menu = KorAP.HintMenu.create("cnx/", list);
739 menu.limit(2);
740 expect(menu.prefix("exit").show()).toBe(false);
741 });
742
743 it('should be navigatable with prefix', function () {
744 var menu = KorAP.HintMenu.create("cnx/", demolist);
745 menu.limit(3);
746
747 expect(menu.show()).toBe(true);
748 expect(menu.prefix()).toEqual("");
749
750 expect(menu.shownItem(0).name()).toEqual("Titel");
751 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
752 expect(menu.shownItem(0).active()).toBe(true);
753 expect(menu.shownItem(1).name()).toEqual("Untertitel");
754 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
755 expect(menu.shownItem(1).active()).toBe(false);
756 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
757 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
758 expect(menu.shownItem(2).active()).toBe(false);
759 expect(menu.shownItem(3)).toBe(undefined);
760
761 menu._prefix.add('a');
762 expect(menu.show()).toBe(true);
763 expect(menu.prefix()).toEqual("a");
764 expect(menu.shownItem(0).name()).toEqual("Autor");
765 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
766
767 menu._prefix.add('u');
768 expect(menu.show()).toBe(true);
769 expect(menu.prefix()).toEqual("au");
770 expect(menu.shownItem(0).name()).toEqual("Autor");
771 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong><mark>Au</mark>tor</strong>");
772
773 menu._prefix.backspace();
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.backspace();
780 expect(menu.show()).toBe(true);
781 expect(menu.prefix()).toEqual("");
782 expect(menu.shownItem(0).name()).toEqual("Titel");
783 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
784 expect(menu.shownItem(0).active()).toBe(true);
785 expect(menu.shownItem(1).name()).toEqual("Untertitel");
786 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
787 expect(menu.shownItem(1).active()).toBe(false);
788 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
789 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
790 expect(menu.shownItem(2).active()).toBe(false);
791 expect(menu.shownItem(3)).toBe(undefined);
792
793 // Forward
794 menu._prefix.backspace();
795 expect(menu.show()).toBe(true);
796 expect(menu.prefix()).toEqual("");
797 expect(menu.shownItem(0).name()).toEqual("Titel");
798 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
799 expect(menu.shownItem(0).active()).toBe(true);
800 expect(menu.shownItem(1).name()).toEqual("Untertitel");
801 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
802 expect(menu.shownItem(1).active()).toBe(false);
803 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
804 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
805 expect(menu.shownItem(2).active()).toBe(false);
806
807 // Forward
808 menu.next();
809 expect(menu.prefix()).toEqual("");
810 expect(menu.shownItem(0).name()).toEqual("Titel");
811 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
812 expect(menu.shownItem(0).active()).toBe(false);
813 expect(menu.shownItem(1).name()).toEqual("Untertitel");
814 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
815 expect(menu.shownItem(1).active()).toBe(true);
816 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
817 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
818 expect(menu.shownItem(2).active()).toBe(false);
819 expect(menu.shownItem(3)).toBe(undefined);
820
821 // Forward
822 menu.next();
823 expect(menu.prefix()).toEqual("");
824 expect(menu.shownItem(0).name()).toEqual("Titel");
825 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
826 expect(menu.shownItem(0).active()).toBe(false);
827 expect(menu.shownItem(1).name()).toEqual("Untertitel");
828 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
829 expect(menu.shownItem(1).active()).toBe(false);
830 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
831 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
832 expect(menu.shownItem(2).active()).toBe(true);
833 expect(menu.shownItem(3)).toBe(undefined);
834
835 // Forward
836 menu.next();
837 expect(menu.prefix()).toEqual("");
838 expect(menu.shownItem(0).name()).toEqual("Untertitel");
839 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Untertitel</strong>");
840 expect(menu.shownItem(0).active()).toBe(false);
841 expect(menu.shownItem(1).name()).toEqual("Veröffentlichungsdatum");
842 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
843 expect(menu.shownItem(1).active()).toBe(false);
844 expect(menu.shownItem(2).name()).toEqual("Länge");
845 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Länge</strong>");
846 expect(menu.shownItem(2).active()).toBe(true);
847 expect(menu.shownItem(3)).toBe(undefined);
848
849 // Forward
850 menu.next();
851 expect(menu.prefix()).toEqual("");
852 expect(menu.shownItem(0).name()).toEqual("Veröffentlichungsdatum");
853 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
854 expect(menu.shownItem(0).active()).toBe(false);
855 expect(menu.shownItem(1).name()).toEqual("Länge");
856 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Länge</strong>");
857 expect(menu.shownItem(1).active()).toBe(false);
858 expect(menu.shownItem(2).name()).toEqual("Autor");
859 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Autor</strong>");
860 expect(menu.shownItem(2).active()).toBe(true);
861 expect(menu.shownItem(3)).toBe(undefined);
862
863 // Forward
864 menu.next();
865 expect(menu.prefix()).toEqual("");
866 expect(menu.shownItem(0).name()).toEqual("Titel");
867 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>");
868 expect(menu.shownItem(0).active()).toBe(true);
869 expect(menu.shownItem(1).name()).toEqual("Untertitel");
870 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>");
871 expect(menu.shownItem(1).active()).toBe(false);
872 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
873 expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
874 expect(menu.shownItem(2).active()).toBe(false);
875
876 });
877
878
879 it('should be navigatable with a prefix (1)', function () {
880 var menu = KorAP.HintMenu.create("cnx/", demolist);
881 menu.limit(3);
882
883 expect(menu.show()).toBe(true);
884 expect(menu.prefix()).toEqual("");
885
886 menu.prefix('el');
887 expect(menu.show()).toBe(true);
888
889 expect(menu.prefix()).toEqual("el");
890 expect(menu._prefix.active()).toEqual(false);
891 expect(menu.shownItem(0).name()).toEqual("Titel");
892 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
893 expect(menu.shownItem(0).active()).toBe(true);
894 expect(menu.shownItem(1).name()).toEqual("Untertitel");
895 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
896 expect(menu.shownItem(1).active()).toBe(false);
897 expect(menu.shownItem(2)).toBe(undefined);
898
899 // Forward
900 menu.next();
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(false);
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(true);
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(true);
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(false);
921 expect(menu.shownItem(2)).toBe(undefined);
922
923
924 // Backward
925 menu.prev();
926 expect(menu.prefix()).toEqual("el");
927 expect(menu._prefix.active()).toEqual(false);
928 expect(menu.shownItem(0).name()).toEqual("Titel");
929 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
930 expect(menu.shownItem(0).active()).toBe(false);
Nils Diewald2d210752015-03-09 19:01:15 +0000931
Nils Diewald5975d702015-03-09 17:45:42 +0000932 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
Nils Diewald2d210752015-03-09 19:01:15 +0000938 it('should be navigatable with a prefix (2)', function () {
Nils Diewald5975d702015-03-09 17:45:42 +0000939 var menu = KorAP.HintMenu.create("cnx/", demolist);
940 menu.limit(3);
941 expect(menu.show()).toBe(true);
942 expect(menu.prefix()).toEqual("");
943 menu.prefix('el');
944 expect(menu.show()).toBe(true);
945
Nils Diewald2d210752015-03-09 19:01:15 +0000946
Nils Diewald5975d702015-03-09 17:45:42 +0000947 expect(menu.prefix()).toEqual("el");
948 expect(menu._prefix.active()).toEqual(false);
949 expect(menu.shownItem(0).name()).toEqual("Titel");
950 expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
951 expect(menu.shownItem(0).active()).toBe(true);
952 expect(menu.shownItem(1).name()).toEqual("Untertitel");
953 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
954 expect(menu.shownItem(1).active()).toBe(false);
955 expect(menu.shownItem(2)).toBe(undefined);
956
957 // Backward
958 menu.prev();
959 expect(menu._prefix.active()).toEqual(true);
Nils Diewald2d210752015-03-09 19:01:15 +0000960
Nils Diewald5975d702015-03-09 17:45:42 +0000961 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(false);
Nils Diewald2d210752015-03-09 19:01:15 +0000964
Nils Diewald5975d702015-03-09 17:45:42 +0000965 expect(menu.shownItem(1).name()).toEqual("Untertitel");
966 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
967 expect(menu.shownItem(1).active()).toBe(false);
968 expect(menu.shownItem(2)).toBe(undefined);
969
970 // Backward
Nils Diewald5975d702015-03-09 17:45:42 +0000971 menu.prev();
972 expect(menu._prefix.active()).toEqual(false);
973 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);
976 expect(menu.shownItem(1).name()).toEqual("Untertitel");
977 expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
978 expect(menu.shownItem(1).active()).toBe(true);
979 expect(menu.shownItem(2)).toBe(undefined);
Nils Diewald5975d702015-03-09 17:45:42 +0000980 });
981
982 xit('should be page downable');
983 xit('should be page upable');
Nils Diewaldfda29d92015-01-22 17:28:01 +0000984});