blob: 225ac3761c7209a85586026a10757786b6ca7aef [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=");
Akronee9ef4a2016-06-03 12:50:08 +0200140 expect(analyzer.test("")).toEqual(undefined);
141 expect(analyzer.test("abcdecnx/")).toEqual("abcdecnx/");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000142 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000143 });
144
Nils Diewald19ccee92014-12-08 11:30:08 +0000145
Nils Diewald7c8ced22015-04-15 19:21:00 +0000146 describe('KorAP.Hint', function () {
147 KorAP.hintArray = {
148 "corenlp/" : [
149 ["Named Entity", "ne=" , "Combined"],
150 ["Named Entity", "ne_dewac_175m_600=" , "ne_dewac_175m_600"],
151 ["Named Entity", "ne_hgc_175m_600=", "ne_hgc_175m_600"]
152 ]
153 };
Nils Diewald19ccee92014-12-08 11:30:08 +0000154
Nils Diewald7c8ced22015-04-15 19:21:00 +0000155 beforeEach(function () {
156 input = document.createElement("input");
157 input.setAttribute("type", "text");
158 input.setAttribute("value", "abcdefghijklmno");
159 input.style.position = 'absolute';
160 input.style.top = "20px";
161 input.style.left = "30px";
162 input.focus();
163 input.selectionStart = 5;
164 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000165
Nils Diewald7c8ced22015-04-15 19:21:00 +0000166 it('should be initializable', function () {
167 // Supports: context, searchField
168 var hint = hintClass.create({
169 inputField : input
170 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000171
Nils Diewald7c8ced22015-04-15 19:21:00 +0000172 expect(hint).toBeTruthy();
173 });
Akron00cd4d12016-05-31 21:01:11 +0200174
175 it('should alert at char pos', function () {
176 var hint = hintClass.create({
177 inputField : input
178 });
179
180 expect(hint.active()).toBeFalsy();
181
182 expect(hint.alert(4, 'That does not work!')).toBeTruthy();
183
184 expect(hint.active()).toBeTruthy();
185
186 var container = hint.inputField().container();
187 expect(container.firstChild.classList.contains('hint')).toBe(true);
188 expect(container.firstChild.classList.contains('alert')).toBe(true);
189 expect(container.firstChild.textContent).toEqual('That does not work!');
190 expect(hint.inputField().mirrorValue()).toEqual('abcd');
191
192 expect(hint.alert(4, 'That does not work!')).toBeFalsy();
193
194 // Update - meaning: hide alert
195 hint.update();
196
197 expect(hint.alert().active).toBeFalsy();
198
199 expect(hint.active()).toBeFalsy();
Akronee9ef4a2016-06-03 12:50:08 +0200200 });
Akron00cd4d12016-05-31 21:01:11 +0200201
Akronee9ef4a2016-06-03 12:50:08 +0200202 it('should view main menu on default', function () {
203 var hint = hintClass.create({
204 inputField : input
205 });
206
207 expect(hint.active()).toBeFalsy();
208
209 hint.inputField().insert('der Baum corenlp/');
210 expect(hint.inputField().container().getElementsByTagName('div').length).toBe(1);
211 expect(hint.inputField().container().getElementsByTagName('ul').length).toBe(0);
212
213 // show with context
214 hint.unshow();
215 hint.show(true);
216
217 expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(4);
218 expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(1);
219
220 hint.inputField().insert(' hhhh');
221 // show with context
222 hint.unshow();
223 hint.show(true);
224
225 expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(4);
226 expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(1);
227
228 hint.unshow();
229 hint.inputField().insert(' aaaa/');
230
231 // show with context
232 hint.show(true);
233
234 console.log(hint.inputField().container().outerHTML);
235
236 expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(4);
237 expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(1);
Akron00cd4d12016-05-31 21:01:11 +0200238 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000239 });
240
Nils Diewald7c8ced22015-04-15 19:21:00 +0000241 describe('KorAP.HintMenuItem', function () {
242 it('should be initializable', function () {
243 expect(
244 function() { menuItemClass.create([]) }
245 ).toThrow(new Error("Missing parameters"));
Nils Diewald19ccee92014-12-08 11:30:08 +0000246
Nils Diewald7c8ced22015-04-15 19:21:00 +0000247 expect(
248 function() { menuItemClass.create(['CoreNLP']) }
249 ).toThrow(new Error("Missing parameters"));
Nils Diewald19ccee92014-12-08 11:30:08 +0000250
Nils Diewald7c8ced22015-04-15 19:21:00 +0000251 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
252 expect(menuItem.name()).toEqual('CoreNLP');
253 expect(menuItem.action()).toEqual('corenlp/');
254 expect(menuItem.desc()).toBeUndefined();
Nils Diewald19ccee92014-12-08 11:30:08 +0000255
Nils Diewald7c8ced22015-04-15 19:21:00 +0000256 menuItem = menuItemClass.create(
257 ['CoreNLP', 'corenlp/', 'It\'s funny']
258 );
259 expect(menuItem.name()).toEqual('CoreNLP');
260 expect(menuItem.action()).toEqual('corenlp/');
261 expect(menuItem.desc()).not.toBeUndefined();
262 expect(menuItem.desc()).toEqual('It\'s funny');
263 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000264
Nils Diewald7c8ced22015-04-15 19:21:00 +0000265 it('should have an element', function () {
266 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
267 expect(menuItem.element()).not.toBe(undefined);
268 expect(menuItem.element().nodeName).toEqual("LI");
Nils Diewald19ccee92014-12-08 11:30:08 +0000269
Nils Diewald7c8ced22015-04-15 19:21:00 +0000270 var title = menuItem.element().firstChild;
271 expect(title.nodeName).toEqual("SPAN");
272 expect(title.firstChild.nodeType).toEqual(3);
273 expect(title.firstChild.nodeValue).toEqual("CoreNLP");
274 expect(menuItem.element().childNodes[0]).not.toBe(undefined);
275 expect(menuItem.element().childNodes[1]).toBe(undefined);
Nils Diewald19ccee92014-12-08 11:30:08 +0000276
Nils Diewald7c8ced22015-04-15 19:21:00 +0000277 menuItem = menuItemClass.create(
278 ['CoreNLP', 'corenlp/', 'my DescRiption']
279 );
280 expect(menuItem.element()).not.toBe(undefined);
281 expect(menuItem.element().nodeName).toEqual("LI");
Nils Diewald19ccee92014-12-08 11:30:08 +0000282
Nils Diewald7c8ced22015-04-15 19:21:00 +0000283 title = menuItem.element().firstChild;
284 expect(title.nodeName).toEqual("SPAN");
285 expect(title.firstChild.nodeType).toEqual(3); // TextNode
286 expect(title.firstChild.nodeValue).toEqual("CoreNLP");
Nils Diewald19ccee92014-12-08 11:30:08 +0000287
Nils Diewald7c8ced22015-04-15 19:21:00 +0000288 expect(menuItem.element().childNodes[0]).not.toBe(undefined);
289 expect(menuItem.element().childNodes[1]).not.toBe(undefined);
Nils Diewald19ccee92014-12-08 11:30:08 +0000290
Nils Diewald7c8ced22015-04-15 19:21:00 +0000291 var desc = menuItem.element().lastChild;
292 expect(desc.nodeName).toEqual("SPAN");
293 expect(desc.firstChild.nodeType).toEqual(3); // TextNode
294 expect(desc.firstChild.nodeValue).toEqual("my DescRiption");
295 });
Nils Diewald1c546922015-04-13 01:56:19 +0000296
Nils Diewald19ccee92014-12-08 11:30:08 +0000297
Nils Diewald7c8ced22015-04-15 19:21:00 +0000298 it('should be activatable and deactivateable by class', function () {
299 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
300 expect(menuItem.active()).toBe(false);
301 expect(menuItem.element().getAttribute("class")).toBe(null);
302 menuItem.active(true);
303 expect(menuItem.active()).toBe(true);
304 expect(menuItem.element().getAttribute("class")).toEqual("active");
305 menuItem.active(false); // Is active
306 expect(menuItem.active()).toBe(false);
307 expect(menuItem.element().getAttribute("class")).toEqual("");
308 menuItem.active(true);
309 expect(menuItem.active()).toBe(true);
310 expect(menuItem.element().getAttribute("class")).toEqual("active");
Nils Diewald19ccee92014-12-08 11:30:08 +0000311
Nils Diewald7c8ced22015-04-15 19:21:00 +0000312 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
313 expect(menuItem.active()).toBe(false);
314 expect(menuItem.element().getAttribute("class")).toBe(null);
315 menuItem.active(false); // Is not active
316 expect(menuItem.active()).toBe(false);
317 expect(menuItem.element().getAttribute("class")).toBe(null);
318 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000319
Nils Diewald7c8ced22015-04-15 19:21:00 +0000320 it('should be set to boundary', function () {
321 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
322 expect(menuItem.active()).toBe(false);
323 expect(menuItem.element().getAttribute("class")).toBe(null);
Nils Diewald19ccee92014-12-08 11:30:08 +0000324
Nils Diewald7c8ced22015-04-15 19:21:00 +0000325 // Set active
326 menuItem.active(true);
327 expect(menuItem.active()).toBe(true);
328 expect(menuItem.noMore()).toBe(false);
329 expect(menuItem.element().getAttribute("class")).toEqual("active");
Nils Diewald19ccee92014-12-08 11:30:08 +0000330
Nils Diewald7c8ced22015-04-15 19:21:00 +0000331 // Set no more
332 menuItem.noMore(true);
333 expect(menuItem.active()).toBe(true);
334 expect(menuItem.noMore()).toBe(true);
335 expect(menuItem.element().getAttribute("class")).toEqual("active no-more");
Nils Diewald1c546922015-04-13 01:56:19 +0000336
Nils Diewald7c8ced22015-04-15 19:21:00 +0000337 // No no more
338 menuItem.noMore(false);
339 expect(menuItem.active()).toBe(true);
340 expect(menuItem.noMore()).toBe(false);
341 expect(menuItem.element().getAttribute("class")).toEqual("active");
Nils Diewald1c546922015-04-13 01:56:19 +0000342
Nils Diewald7c8ced22015-04-15 19:21:00 +0000343 // Set no more, deactivate
344 menuItem.noMore(true);
345 menuItem.active(false);
346 expect(menuItem.active()).toBe(false);
347 expect(menuItem.noMore()).toBe(true);
348 expect(menuItem.element().getAttribute("class")).toEqual("no-more");
Nils Diewald19ccee92014-12-08 11:30:08 +0000349
Nils Diewald7c8ced22015-04-15 19:21:00 +0000350 // Set active
351 menuItem.active(true);
352 expect(menuItem.active()).toBe(true);
353 expect(menuItem.noMore()).toBe(true);
354 expect(menuItem.element().getAttribute("class")).toEqual("no-more active");
355 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000356
Nils Diewald7c8ced22015-04-15 19:21:00 +0000357 it('should be highlightable', function () {
358 // Highlight in the middle
359 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
360 menuItem.highlight("ren");
361 expect(menuItem.element().innerHTML).toEqual("<span>Co<mark>reN</mark>LP</span>");
Nils Diewald19ccee92014-12-08 11:30:08 +0000362
Nils Diewald7c8ced22015-04-15 19:21:00 +0000363 menuItem.lowlight();
364 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
Nils Diewald19ccee92014-12-08 11:30:08 +0000365
Nils Diewald7c8ced22015-04-15 19:21:00 +0000366 // Starting highlight
367 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
368 menuItem.highlight("cor");
369 expect(menuItem.element().innerHTML).toEqual("<span><mark>Cor</mark>eNLP</span>");
Nils Diewald19ccee92014-12-08 11:30:08 +0000370
Nils Diewald7c8ced22015-04-15 19:21:00 +0000371 menuItem.lowlight();
372 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
373
374 // Starting highlight - short
375 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
376 menuItem.highlight("c");
377 expect(menuItem.element().innerHTML).toEqual("<span><mark>C</mark>oreNLP</span>");
378
379 menuItem.lowlight();
380 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
381
382 // Highlight at the end
383 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
384 menuItem.highlight("nlp");
385 expect(menuItem.element().innerHTML).toEqual("<span>Core<mark>NLP</mark></span>");
386
387 menuItem.lowlight();
388 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
389
390 // Highlight at the end - short
391 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
392 menuItem.highlight("p");
393 expect(menuItem.element().innerHTML).toEqual("<span>CoreNL<mark>P</mark></span>");
394
395 menuItem.lowlight();
396 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
397
398 // No highlight
399 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
400 menuItem.highlight("xp");
401 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
402
403 menuItem.lowlight();
404 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
405
406 // Highlight in the middle - first
407 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
408
409 menuItem.highlight("ren");
410 expect(menuItem.element().innerHTML).toEqual("<span>Co<mark>reN</mark>LP</span><span class=\"desc\">This is my Example</span>");
411
412 menuItem.lowlight();
413 expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Example</span>');
414
415 // Highlight in the middle - second
416 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
417 menuItem.highlight("ampl");
418 expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Ex<mark>ampl</mark>e</span>');
419
420 menuItem.lowlight();
421 expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Example</span>');
422
423 // Highlight in the middle - both
424 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
425
426 menuItem.highlight("e");
427 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>');
428
429 menuItem.lowlight();
430 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>");
431
432 // Highlight in the end - second
433 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
434 menuItem.highlight("le");
435 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Examp<mark>le</mark></span>");
436
437 menuItem.lowlight();
438 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>");
439
440 // Highlight at the beginning - second
441 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
442 menuItem.highlight("this");
443 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\"><mark>This</mark> is my Example</span>");
444
445 menuItem.lowlight();
446 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>");
Akron6ed13992016-05-23 18:06:05 +0200447
Nils Diewald7c8ced22015-04-15 19:21:00 +0000448 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000449 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000450
Nils Diewald7c8ced22015-04-15 19:21:00 +0000451 describe('KorAP.HintMenu', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000452 var list = [
453 ["Constituency", "c=", "Example 1"],
454 ["Lemma", "l="],
455 ["Morphology", "m=", "Example 2"],
456 ["Part-of-Speech", "p="],
457 ["Syntax", "syn="]
458 ];
Nils Diewald19ccee92014-12-08 11:30:08 +0000459
Nils Diewald7c8ced22015-04-15 19:21:00 +0000460 it('should be initializable', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000461 var menu = menuClass.create(null, "cnx/", list);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000462 expect(menu.element().nodeName).toEqual('UL');
463 expect(menu.element().style.opacity).toEqual("0");
Nils Diewald19ccee92014-12-08 11:30:08 +0000464
Nils Diewald7c8ced22015-04-15 19:21:00 +0000465 menu.limit(8);
Nils Diewald19ccee92014-12-08 11:30:08 +0000466
Nils Diewald7c8ced22015-04-15 19:21:00 +0000467 // view
468 menu.show();
Akron6ed13992016-05-23 18:06:05 +0200469 expect(menu.prefix()).toBe('');
Nils Diewald19ccee92014-12-08 11:30:08 +0000470
Nils Diewald7c8ced22015-04-15 19:21:00 +0000471 // First element in list
472 expect(menu.item(0).active()).toBe(true);
473 expect(menu.item(0).noMore()).toBe(true);
474
475 // Middle element in list
476 expect(menu.item(2).active()).toBe(false);
477 expect(menu.item(2).noMore()).toBe(false);
Nils Diewald19ccee92014-12-08 11:30:08 +0000478
Nils Diewald7c8ced22015-04-15 19:21:00 +0000479 // Last element in list
480 expect(menu.item(menu.length() - 1).active()).toBe(false);
481 expect(menu.item(menu.length() - 1).noMore()).toBe(true);
Akron6ed13992016-05-23 18:06:05 +0200482
483 expect(menu.shownItem(0).active()).toBeTruthy();
484 expect(menu.shownItem(0).lcField()).toEqual(' constituency example 1');
485 expect(menu.shownItem(1).lcField()).toEqual(' lemma');
486 expect(menu.shownItem(2).lcField()).toEqual(' morphology example 2');
487
488 menu.next();
489 expect(menu.shownItem(1).active()).toBeTruthy();
490
491 menu.next();
492 expect(menu.shownItem(2).active()).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000493 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000494 });
495});