blob: c944410466462a0275c56d4f2ab36a45b4682c2e [file] [log] [blame]
Nils Diewald19ccee92014-12-08 11:30:08 +00001function emitKeyboardEvent (element, type, keyCode) {
2 // event type : keydown, keyup, keypress
3 // http://stackoverflow.com/questions/596481/simulate-javascript-key-events
4 // http://stackoverflow.com/questions/961532/firing-a-keyboard-event-in-javascript
5 var keyboardEvent = document.createEvent("KeyboardEvent");
6 var initMethod = typeof keyboardEvent.initKeyboardEvent !== 'undefined' ?
7 "initKeyboardEvent" : "initKeyEvent";
Nils Diewald19ccee92014-12-08 11:30:08 +00008 keyboardEvent[initMethod](
9 type,
Akron308db382016-05-30 22:34:07 +020010 true, // bubbles
11 true, // cancelable
12 window, // viewArg: should be window
13 false, // ctrlKeyArg
14 false, // altKeyArg
15 false, // shiftKeyArg
16 false, // metaKeyArg
Nils Diewald19ccee92014-12-08 11:30:08 +000017 keyCode, // keyCodeArg : unsigned long the virtual key code, else 0
Akron308db382016-05-30 22:34:07 +020018 0 // charCodeArgs : unsigned long the Unicode character
19 // associated with the depressed key, else 0
Nils Diewald19ccee92014-12-08 11:30:08 +000020 );
Nils Diewald19ccee92014-12-08 11:30:08 +000021 element.dispatchEvent(keyboardEvent);
22};
23
24
Nils Diewald7c8ced22015-04-15 19:21:00 +000025define(['hint'], function () {
Nils Diewald5c5a7472015-04-02 22:13:38 +000026
Nils Diewald7c8ced22015-04-15 19:21:00 +000027 var hintClass = require("hint");
28 var inputClass = require("hint/input");
29 var contextClass = require("hint/contextanalyzer");
30 var menuClass = require("hint/menu");
31 var menuItemClass = require("hint/item");
Nils Diewald5c5a7472015-04-02 22:13:38 +000032
Nils Diewald7c8ced22015-04-15 19:21:00 +000033 describe('KorAP.InputField', function () {
34 var input;
Nils Diewald1c546922015-04-13 01:56:19 +000035
Nils Diewald7c8ced22015-04-15 19:21:00 +000036 beforeEach(function () {
37 input = document.createElement("input");
38 input.setAttribute('type', "text");
39 input.setAttribute("value", "abcdefghijklmno");
40 input.style.position = 'absolute';
41 document.getElementsByTagName('body')[0].appendChild(input);
42 input.style.top = "20px";
43 input.style.left = "30px";
44 input.focus();
45 input.selectionStart = 5;
Nils Diewald5c5a7472015-04-02 22:13:38 +000046 });
47
Nils Diewald7c8ced22015-04-15 19:21:00 +000048 afterEach(function () {
49 document.getElementsByTagName("body")[0].removeChild(
50 input
51 );
52 });
Nils Diewald5c5a7472015-04-02 22:13:38 +000053
Nils Diewald7c8ced22015-04-15 19:21:00 +000054 afterAll(function () {
55 try {
Akron00cd4d12016-05-31 21:01:11 +020056 var mirrors = document.querySelectorAll(".hint.mirror");
57 for (var i in mirrors) {
58 mirrors[i].parentNode.removeChild(mirrors[i])
59 };
Nils Diewald7c8ced22015-04-15 19:21:00 +000060 }
61 catch (e) {};
62 });
Nils Diewald19ccee92014-12-08 11:30:08 +000063
Nils Diewald7c8ced22015-04-15 19:21:00 +000064 it('should be initializable', function () {
65 // Supports: context, searchField
66 var inputField = inputClass.create(input);
67 expect(inputField._element).not.toBe(undefined);
68 });
Nils Diewald19ccee92014-12-08 11:30:08 +000069
Nils Diewald7c8ced22015-04-15 19:21:00 +000070 it('should have text', function () {
71 expect(input.value).toEqual('abcdefghijklmno');
72 var inputField = inputClass.create(input);
Nils Diewald19ccee92014-12-08 11:30:08 +000073
Nils Diewald7c8ced22015-04-15 19:21:00 +000074 expect(inputField.value()).toEqual("abcdefghijklmno");
Nils Diewald19ccee92014-12-08 11:30:08 +000075
Nils Diewald7c8ced22015-04-15 19:21:00 +000076 expect(input.selectionStart).toEqual(5);
77 expect(inputField.element().selectionStart).toEqual(5);
Nils Diewald7148c6f2015-05-04 15:07:53 +000078 expect(inputField._split()[0]).toEqual("abcde");
79 expect(inputField._split()[1]).toEqual("fghijklmno");
Nils Diewald19ccee92014-12-08 11:30:08 +000080
Nils Diewald7c8ced22015-04-15 19:21:00 +000081 inputField.insert("xyz");
82 expect(inputField.value()).toEqual('abcdexyzfghijklmno');
Nils Diewald7148c6f2015-05-04 15:07:53 +000083 expect(inputField._split()[0]).toEqual("abcdexyz");
84 expect(inputField._split()[1]).toEqual("fghijklmno");
Nils Diewald7c8ced22015-04-15 19:21:00 +000085 });
Nils Diewald19ccee92014-12-08 11:30:08 +000086
Nils Diewald7c8ced22015-04-15 19:21:00 +000087 it('should be correctly positioned', function () {
88 expect(input.value).toEqual('abcdefghijklmno');
89 var inputField = inputClass.create(input);
90 document.getElementsByTagName("body")[0].appendChild(input);
91 inputField.reposition();
92 expect(input.style.left).toEqual("30px");
93 expect(inputField.mirror().style.left.match(/^(\d+)px$/)[1]).toBeGreaterThan(29);
94 expect(inputField.mirror().style.top.match(/^(\d+)px$/)[1]).toBeGreaterThan(20);
95 });
Nils Diewald19ccee92014-12-08 11:30:08 +000096
Nils Diewald7c8ced22015-04-15 19:21:00 +000097 it('should have a correct context', function () {
98 expect(input.value).toEqual('abcdefghijklmno');
99 var inputField = inputClass.create(input);
100 expect(inputField.value()).toEqual("abcdefghijklmno");
101 expect(inputField.element().selectionStart).toEqual(5);
Nils Diewald7148c6f2015-05-04 15:07:53 +0000102 expect(inputField._split()[0]).toEqual("abcde");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000103 expect(inputField.context()).toEqual("abcde");
104 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000105
Nils Diewald7c8ced22015-04-15 19:21:00 +0000106 /*
107 it('should be correctly triggerable', function () {
108 // https://developer.mozilla.org/samples/domref/dispatchEvent.html
109 var hint = KorAP.Hint.create({ "inputField" : input });
110 emitKeyboardEvent(hint.inputField.element, "keypress", 20);
111 });
112 */
Nils Diewald19ccee92014-12-08 11:30:08 +0000113 });
114
Nils Diewald1c546922015-04-13 01:56:19 +0000115
Nils Diewald7c8ced22015-04-15 19:21:00 +0000116 describe('KorAP.ContextAnalyzer', function () {
117 it('should be initializable', function () {
118 var analyzer = contextClass.create(")");
119 expect(analyzer).toBe(undefined);
120 analyzer = contextClass.create(".+?");
121 expect(analyzer).not.toBe(undefined);
122 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000123
Nils Diewald7c8ced22015-04-15 19:21:00 +0000124 it('should check correctly', function () {
125 analyzer = contextClass.create(KorAP.context);
126 expect(analyzer.test("cnx/]cnx/c=")).toEqual("cnx/c=");
127 expect(analyzer.test("cnx/c=")).toEqual("cnx/c=");
128 expect(analyzer.test("cnx/c=np mate/m=mood:")).toEqual("mate/m=mood:");
129 expect(analyzer.test("impcnx/")).toEqual("impcnx/");
130 expect(analyzer.test("cnx/c=npcnx/")).toEqual("npcnx/");
131 expect(analyzer.test("mate/m=degree:pos corenlp/ne_dewac_175m_600="))
132 .toEqual("corenlp/ne_dewac_175m_600=");
Akron113cc1a2016-01-22 21:17:57 +0100133 expect(analyzer.test("corenlp/")).toEqual("corenlp/");
134 expect(analyzer.test("corenlp/c=")).toEqual("corenlp/c=");
135 expect(analyzer.test("corenlp/c=PP-")).toEqual("corenlp/c=PP-");
136 expect(analyzer.test("corenlp/c=XY-")).toEqual("corenlp/c=XY-");
Akroncff9bac2016-01-25 21:39:38 +0100137 expect(analyzer.test("sgbr/l=")).toEqual("sgbr/l=");
138 expect(analyzer.test("sgbr/lv=")).toEqual("sgbr/lv=");
139 expect(analyzer.test("sgbr/p=")).toEqual("sgbr/p=");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000140 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000141 });
142
Nils Diewald19ccee92014-12-08 11:30:08 +0000143
Nils Diewald7c8ced22015-04-15 19:21:00 +0000144 describe('KorAP.Hint', function () {
145 KorAP.hintArray = {
146 "corenlp/" : [
147 ["Named Entity", "ne=" , "Combined"],
148 ["Named Entity", "ne_dewac_175m_600=" , "ne_dewac_175m_600"],
149 ["Named Entity", "ne_hgc_175m_600=", "ne_hgc_175m_600"]
150 ]
151 };
Nils Diewald19ccee92014-12-08 11:30:08 +0000152
Nils Diewald7c8ced22015-04-15 19:21:00 +0000153 beforeEach(function () {
154 input = document.createElement("input");
155 input.setAttribute("type", "text");
156 input.setAttribute("value", "abcdefghijklmno");
157 input.style.position = 'absolute';
158 input.style.top = "20px";
159 input.style.left = "30px";
160 input.focus();
161 input.selectionStart = 5;
162 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000163
Nils Diewald7c8ced22015-04-15 19:21:00 +0000164 it('should be initializable', function () {
165 // Supports: context, searchField
166 var hint = hintClass.create({
167 inputField : input
168 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000169
Nils Diewald7c8ced22015-04-15 19:21:00 +0000170 expect(hint).toBeTruthy();
171 });
Akron00cd4d12016-05-31 21:01:11 +0200172
173 it('should alert at char pos', function () {
174 var hint = hintClass.create({
175 inputField : input
176 });
177
178 expect(hint.active()).toBeFalsy();
179
180 expect(hint.alert(4, 'That does not work!')).toBeTruthy();
181
182 expect(hint.active()).toBeTruthy();
183
184 var container = hint.inputField().container();
185 expect(container.firstChild.classList.contains('hint')).toBe(true);
186 expect(container.firstChild.classList.contains('alert')).toBe(true);
187 expect(container.firstChild.textContent).toEqual('That does not work!');
188 expect(hint.inputField().mirrorValue()).toEqual('abcd');
189
190 expect(hint.alert(4, 'That does not work!')).toBeFalsy();
191
192 // Update - meaning: hide alert
193 hint.update();
194
195 expect(hint.alert().active).toBeFalsy();
196
197 expect(hint.active()).toBeFalsy();
198
199 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000200 });
201
Nils Diewald7c8ced22015-04-15 19:21:00 +0000202 describe('KorAP.HintMenuItem', function () {
203 it('should be initializable', function () {
204 expect(
205 function() { menuItemClass.create([]) }
206 ).toThrow(new Error("Missing parameters"));
Nils Diewald19ccee92014-12-08 11:30:08 +0000207
Nils Diewald7c8ced22015-04-15 19:21:00 +0000208 expect(
209 function() { menuItemClass.create(['CoreNLP']) }
210 ).toThrow(new Error("Missing parameters"));
Nils Diewald19ccee92014-12-08 11:30:08 +0000211
Nils Diewald7c8ced22015-04-15 19:21:00 +0000212 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
213 expect(menuItem.name()).toEqual('CoreNLP');
214 expect(menuItem.action()).toEqual('corenlp/');
215 expect(menuItem.desc()).toBeUndefined();
Nils Diewald19ccee92014-12-08 11:30:08 +0000216
Nils Diewald7c8ced22015-04-15 19:21:00 +0000217 menuItem = menuItemClass.create(
218 ['CoreNLP', 'corenlp/', 'It\'s funny']
219 );
220 expect(menuItem.name()).toEqual('CoreNLP');
221 expect(menuItem.action()).toEqual('corenlp/');
222 expect(menuItem.desc()).not.toBeUndefined();
223 expect(menuItem.desc()).toEqual('It\'s funny');
224 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000225
Nils Diewald7c8ced22015-04-15 19:21:00 +0000226 it('should have an element', function () {
227 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
228 expect(menuItem.element()).not.toBe(undefined);
229 expect(menuItem.element().nodeName).toEqual("LI");
Nils Diewald19ccee92014-12-08 11:30:08 +0000230
Nils Diewald7c8ced22015-04-15 19:21:00 +0000231 var title = menuItem.element().firstChild;
232 expect(title.nodeName).toEqual("SPAN");
233 expect(title.firstChild.nodeType).toEqual(3);
234 expect(title.firstChild.nodeValue).toEqual("CoreNLP");
235 expect(menuItem.element().childNodes[0]).not.toBe(undefined);
236 expect(menuItem.element().childNodes[1]).toBe(undefined);
Nils Diewald19ccee92014-12-08 11:30:08 +0000237
Nils Diewald7c8ced22015-04-15 19:21:00 +0000238 menuItem = menuItemClass.create(
239 ['CoreNLP', 'corenlp/', 'my DescRiption']
240 );
241 expect(menuItem.element()).not.toBe(undefined);
242 expect(menuItem.element().nodeName).toEqual("LI");
Nils Diewald19ccee92014-12-08 11:30:08 +0000243
Nils Diewald7c8ced22015-04-15 19:21:00 +0000244 title = menuItem.element().firstChild;
245 expect(title.nodeName).toEqual("SPAN");
246 expect(title.firstChild.nodeType).toEqual(3); // TextNode
247 expect(title.firstChild.nodeValue).toEqual("CoreNLP");
Nils Diewald19ccee92014-12-08 11:30:08 +0000248
Nils Diewald7c8ced22015-04-15 19:21:00 +0000249 expect(menuItem.element().childNodes[0]).not.toBe(undefined);
250 expect(menuItem.element().childNodes[1]).not.toBe(undefined);
Nils Diewald19ccee92014-12-08 11:30:08 +0000251
Nils Diewald7c8ced22015-04-15 19:21:00 +0000252 var desc = menuItem.element().lastChild;
253 expect(desc.nodeName).toEqual("SPAN");
254 expect(desc.firstChild.nodeType).toEqual(3); // TextNode
255 expect(desc.firstChild.nodeValue).toEqual("my DescRiption");
256 });
Nils Diewald1c546922015-04-13 01:56:19 +0000257
Nils Diewald19ccee92014-12-08 11:30:08 +0000258
Nils Diewald7c8ced22015-04-15 19:21:00 +0000259 it('should be activatable and deactivateable by class', function () {
260 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
261 expect(menuItem.active()).toBe(false);
262 expect(menuItem.element().getAttribute("class")).toBe(null);
263 menuItem.active(true);
264 expect(menuItem.active()).toBe(true);
265 expect(menuItem.element().getAttribute("class")).toEqual("active");
266 menuItem.active(false); // Is active
267 expect(menuItem.active()).toBe(false);
268 expect(menuItem.element().getAttribute("class")).toEqual("");
269 menuItem.active(true);
270 expect(menuItem.active()).toBe(true);
271 expect(menuItem.element().getAttribute("class")).toEqual("active");
Nils Diewald19ccee92014-12-08 11:30:08 +0000272
Nils Diewald7c8ced22015-04-15 19:21:00 +0000273 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
274 expect(menuItem.active()).toBe(false);
275 expect(menuItem.element().getAttribute("class")).toBe(null);
276 menuItem.active(false); // Is not active
277 expect(menuItem.active()).toBe(false);
278 expect(menuItem.element().getAttribute("class")).toBe(null);
279 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000280
Nils Diewald7c8ced22015-04-15 19:21:00 +0000281 it('should be set to boundary', function () {
282 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
283 expect(menuItem.active()).toBe(false);
284 expect(menuItem.element().getAttribute("class")).toBe(null);
Nils Diewald19ccee92014-12-08 11:30:08 +0000285
Nils Diewald7c8ced22015-04-15 19:21:00 +0000286 // Set active
287 menuItem.active(true);
288 expect(menuItem.active()).toBe(true);
289 expect(menuItem.noMore()).toBe(false);
290 expect(menuItem.element().getAttribute("class")).toEqual("active");
Nils Diewald19ccee92014-12-08 11:30:08 +0000291
Nils Diewald7c8ced22015-04-15 19:21:00 +0000292 // Set no more
293 menuItem.noMore(true);
294 expect(menuItem.active()).toBe(true);
295 expect(menuItem.noMore()).toBe(true);
296 expect(menuItem.element().getAttribute("class")).toEqual("active no-more");
Nils Diewald1c546922015-04-13 01:56:19 +0000297
Nils Diewald7c8ced22015-04-15 19:21:00 +0000298 // No no more
299 menuItem.noMore(false);
300 expect(menuItem.active()).toBe(true);
301 expect(menuItem.noMore()).toBe(false);
302 expect(menuItem.element().getAttribute("class")).toEqual("active");
Nils Diewald1c546922015-04-13 01:56:19 +0000303
Nils Diewald7c8ced22015-04-15 19:21:00 +0000304 // Set no more, deactivate
305 menuItem.noMore(true);
306 menuItem.active(false);
307 expect(menuItem.active()).toBe(false);
308 expect(menuItem.noMore()).toBe(true);
309 expect(menuItem.element().getAttribute("class")).toEqual("no-more");
Nils Diewald19ccee92014-12-08 11:30:08 +0000310
Nils Diewald7c8ced22015-04-15 19:21:00 +0000311 // Set active
312 menuItem.active(true);
313 expect(menuItem.active()).toBe(true);
314 expect(menuItem.noMore()).toBe(true);
315 expect(menuItem.element().getAttribute("class")).toEqual("no-more active");
316 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000317
Nils Diewald7c8ced22015-04-15 19:21:00 +0000318 it('should be highlightable', function () {
319 // Highlight in the middle
320 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
321 menuItem.highlight("ren");
322 expect(menuItem.element().innerHTML).toEqual("<span>Co<mark>reN</mark>LP</span>");
Nils Diewald19ccee92014-12-08 11:30:08 +0000323
Nils Diewald7c8ced22015-04-15 19:21:00 +0000324 menuItem.lowlight();
325 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
Nils Diewald19ccee92014-12-08 11:30:08 +0000326
Nils Diewald7c8ced22015-04-15 19:21:00 +0000327 // Starting highlight
328 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
329 menuItem.highlight("cor");
330 expect(menuItem.element().innerHTML).toEqual("<span><mark>Cor</mark>eNLP</span>");
Nils Diewald19ccee92014-12-08 11:30:08 +0000331
Nils Diewald7c8ced22015-04-15 19:21:00 +0000332 menuItem.lowlight();
333 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
334
335 // Starting highlight - short
336 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
337 menuItem.highlight("c");
338 expect(menuItem.element().innerHTML).toEqual("<span><mark>C</mark>oreNLP</span>");
339
340 menuItem.lowlight();
341 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
342
343 // Highlight at the end
344 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
345 menuItem.highlight("nlp");
346 expect(menuItem.element().innerHTML).toEqual("<span>Core<mark>NLP</mark></span>");
347
348 menuItem.lowlight();
349 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
350
351 // Highlight at the end - short
352 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
353 menuItem.highlight("p");
354 expect(menuItem.element().innerHTML).toEqual("<span>CoreNL<mark>P</mark></span>");
355
356 menuItem.lowlight();
357 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
358
359 // No highlight
360 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
361 menuItem.highlight("xp");
362 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
363
364 menuItem.lowlight();
365 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
366
367 // Highlight in the middle - first
368 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
369
370 menuItem.highlight("ren");
371 expect(menuItem.element().innerHTML).toEqual("<span>Co<mark>reN</mark>LP</span><span class=\"desc\">This is my Example</span>");
372
373 menuItem.lowlight();
374 expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Example</span>');
375
376 // Highlight in the middle - second
377 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
378 menuItem.highlight("ampl");
379 expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Ex<mark>ampl</mark>e</span>');
380
381 menuItem.lowlight();
382 expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Example</span>');
383
384 // Highlight in the middle - both
385 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
386
387 menuItem.highlight("e");
388 expect(menuItem.element().innerHTML).toEqual('<span>Cor<mark>e</mark>NLP</span><span class="desc">This is my <mark>E</mark>xampl<mark>e</mark></span>');
389
390 menuItem.lowlight();
391 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>");
392
393 // Highlight in the end - second
394 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
395 menuItem.highlight("le");
396 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Examp<mark>le</mark></span>");
397
398 menuItem.lowlight();
399 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>");
400
401 // Highlight at the beginning - second
402 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
403 menuItem.highlight("this");
404 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\"><mark>This</mark> is my Example</span>");
405
406 menuItem.lowlight();
407 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>");
Akron6ed13992016-05-23 18:06:05 +0200408
Nils Diewald7c8ced22015-04-15 19:21:00 +0000409 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000410 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000411
Nils Diewald7c8ced22015-04-15 19:21:00 +0000412 describe('KorAP.HintMenu', function () {
Nils Diewald19ccee92014-12-08 11:30:08 +0000413
Nils Diewald7c8ced22015-04-15 19:21:00 +0000414 var list = [
415 ["Constituency", "c=", "Example 1"],
416 ["Lemma", "l="],
417 ["Morphology", "m=", "Example 2"],
418 ["Part-of-Speech", "p="],
419 ["Syntax", "syn="]
420 ];
Nils Diewald19ccee92014-12-08 11:30:08 +0000421
Nils Diewald7c8ced22015-04-15 19:21:00 +0000422 it('should be initializable', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000423 var menu = menuClass.create(null, "cnx/", list);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000424 expect(menu.element().nodeName).toEqual('UL');
425 expect(menu.element().style.opacity).toEqual("0");
Nils Diewald19ccee92014-12-08 11:30:08 +0000426
Nils Diewald7c8ced22015-04-15 19:21:00 +0000427 menu.limit(8);
Nils Diewald19ccee92014-12-08 11:30:08 +0000428
Nils Diewald7c8ced22015-04-15 19:21:00 +0000429 // view
430 menu.show();
Akron6ed13992016-05-23 18:06:05 +0200431 expect(menu.prefix()).toBe('');
Nils Diewald19ccee92014-12-08 11:30:08 +0000432
Nils Diewald7c8ced22015-04-15 19:21:00 +0000433 // First element in list
434 expect(menu.item(0).active()).toBe(true);
435 expect(menu.item(0).noMore()).toBe(true);
436
437 // Middle element in list
438 expect(menu.item(2).active()).toBe(false);
439 expect(menu.item(2).noMore()).toBe(false);
Nils Diewald19ccee92014-12-08 11:30:08 +0000440
Nils Diewald7c8ced22015-04-15 19:21:00 +0000441 // Last element in list
442 expect(menu.item(menu.length() - 1).active()).toBe(false);
443 expect(menu.item(menu.length() - 1).noMore()).toBe(true);
Akron6ed13992016-05-23 18:06:05 +0200444
445 expect(menu.shownItem(0).active()).toBeTruthy();
446 expect(menu.shownItem(0).lcField()).toEqual(' constituency example 1');
447 expect(menu.shownItem(1).lcField()).toEqual(' lemma');
448 expect(menu.shownItem(2).lcField()).toEqual(' morphology example 2');
449
450 menu.next();
451 expect(menu.shownItem(1).active()).toBeTruthy();
452
453 menu.next();
454 expect(menu.shownItem(2).active()).toBeTruthy();
455
Nils Diewald7c8ced22015-04-15 19:21:00 +0000456 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000457 });
458});