blob: 0ebb0e4c83a16e4c88b62e90d112243733c74550 [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 Diewald7c8ced22015-04-15 19:21:00 +000026 var hintClass = require("hint");
27 var inputClass = require("hint/input");
28 var contextClass = require("hint/contextanalyzer");
29 var menuClass = require("hint/menu");
30 var menuItemClass = require("hint/item");
Nils Diewald5c5a7472015-04-02 22:13:38 +000031
Nils Diewald7c8ced22015-04-15 19:21:00 +000032 describe('KorAP.InputField', function () {
33 var input;
Nils Diewald1c546922015-04-13 01:56:19 +000034
Nils Diewald7c8ced22015-04-15 19:21:00 +000035 beforeEach(function () {
36 input = document.createElement("input");
37 input.setAttribute('type', "text");
38 input.setAttribute("value", "abcdefghijklmno");
39 input.style.position = 'absolute';
40 document.getElementsByTagName('body')[0].appendChild(input);
41 input.style.top = "20px";
42 input.style.left = "30px";
43 input.focus();
44 input.selectionStart = 5;
Nils Diewald5c5a7472015-04-02 22:13:38 +000045 });
46
Nils Diewald7c8ced22015-04-15 19:21:00 +000047 afterEach(function () {
48 document.getElementsByTagName("body")[0].removeChild(
49 input
50 );
51 });
Nils Diewald5c5a7472015-04-02 22:13:38 +000052
Nils Diewald7c8ced22015-04-15 19:21:00 +000053 afterAll(function () {
54 try {
Akron00cd4d12016-05-31 21:01:11 +020055 var mirrors = document.querySelectorAll(".hint.mirror");
56 for (var i in mirrors) {
57 mirrors[i].parentNode.removeChild(mirrors[i])
58 };
Nils Diewald7c8ced22015-04-15 19:21:00 +000059 }
60 catch (e) {};
61 });
Nils Diewald19ccee92014-12-08 11:30:08 +000062
Nils Diewald7c8ced22015-04-15 19:21:00 +000063 it('should be initializable', function () {
64 // Supports: context, searchField
65 var inputField = inputClass.create(input);
66 expect(inputField._element).not.toBe(undefined);
67 });
Nils Diewald19ccee92014-12-08 11:30:08 +000068
Nils Diewald7c8ced22015-04-15 19:21:00 +000069 it('should have text', function () {
70 expect(input.value).toEqual('abcdefghijklmno');
71 var inputField = inputClass.create(input);
Nils Diewald19ccee92014-12-08 11:30:08 +000072
Nils Diewald7c8ced22015-04-15 19:21:00 +000073 expect(inputField.value()).toEqual("abcdefghijklmno");
Nils Diewald19ccee92014-12-08 11:30:08 +000074
Nils Diewald7c8ced22015-04-15 19:21:00 +000075 expect(input.selectionStart).toEqual(5);
76 expect(inputField.element().selectionStart).toEqual(5);
Nils Diewald7148c6f2015-05-04 15:07:53 +000077 expect(inputField._split()[0]).toEqual("abcde");
78 expect(inputField._split()[1]).toEqual("fghijklmno");
Nils Diewald19ccee92014-12-08 11:30:08 +000079
Nils Diewald7c8ced22015-04-15 19:21:00 +000080 inputField.insert("xyz");
81 expect(inputField.value()).toEqual('abcdexyzfghijklmno');
Nils Diewald7148c6f2015-05-04 15:07:53 +000082 expect(inputField._split()[0]).toEqual("abcdexyz");
83 expect(inputField._split()[1]).toEqual("fghijklmno");
Nils Diewald7c8ced22015-04-15 19:21:00 +000084 });
Nils Diewald19ccee92014-12-08 11:30:08 +000085
Nils Diewald7c8ced22015-04-15 19:21:00 +000086 it('should be correctly positioned', function () {
87 expect(input.value).toEqual('abcdefghijklmno');
88 var inputField = inputClass.create(input);
89 document.getElementsByTagName("body")[0].appendChild(input);
90 inputField.reposition();
91 expect(input.style.left).toEqual("30px");
92 expect(inputField.mirror().style.left.match(/^(\d+)px$/)[1]).toBeGreaterThan(29);
93 expect(inputField.mirror().style.top.match(/^(\d+)px$/)[1]).toBeGreaterThan(20);
94 });
Nils Diewald19ccee92014-12-08 11:30:08 +000095
Nils Diewald7c8ced22015-04-15 19:21:00 +000096 it('should have a correct context', function () {
97 expect(input.value).toEqual('abcdefghijklmno');
98 var inputField = inputClass.create(input);
99 expect(inputField.value()).toEqual("abcdefghijklmno");
100 expect(inputField.element().selectionStart).toEqual(5);
Nils Diewald7148c6f2015-05-04 15:07:53 +0000101 expect(inputField._split()[0]).toEqual("abcde");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000102 expect(inputField.context()).toEqual("abcde");
103 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000104
Nils Diewald7c8ced22015-04-15 19:21:00 +0000105 /*
106 it('should be correctly triggerable', function () {
107 // https://developer.mozilla.org/samples/domref/dispatchEvent.html
108 var hint = KorAP.Hint.create({ "inputField" : input });
109 emitKeyboardEvent(hint.inputField.element, "keypress", 20);
110 });
111 */
Nils Diewald19ccee92014-12-08 11:30:08 +0000112 });
113
Nils Diewald1c546922015-04-13 01:56:19 +0000114
Nils Diewald7c8ced22015-04-15 19:21:00 +0000115 describe('KorAP.ContextAnalyzer', function () {
116 it('should be initializable', function () {
117 var analyzer = contextClass.create(")");
118 expect(analyzer).toBe(undefined);
119 analyzer = contextClass.create(".+?");
120 expect(analyzer).not.toBe(undefined);
121 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000122
Nils Diewald7c8ced22015-04-15 19:21:00 +0000123 it('should check correctly', function () {
124 analyzer = contextClass.create(KorAP.context);
125 expect(analyzer.test("cnx/]cnx/c=")).toEqual("cnx/c=");
126 expect(analyzer.test("cnx/c=")).toEqual("cnx/c=");
127 expect(analyzer.test("cnx/c=np mate/m=mood:")).toEqual("mate/m=mood:");
128 expect(analyzer.test("impcnx/")).toEqual("impcnx/");
129 expect(analyzer.test("cnx/c=npcnx/")).toEqual("npcnx/");
130 expect(analyzer.test("mate/m=degree:pos corenlp/ne_dewac_175m_600="))
131 .toEqual("corenlp/ne_dewac_175m_600=");
Akron113cc1a2016-01-22 21:17:57 +0100132 expect(analyzer.test("corenlp/")).toEqual("corenlp/");
133 expect(analyzer.test("corenlp/c=")).toEqual("corenlp/c=");
134 expect(analyzer.test("corenlp/c=PP-")).toEqual("corenlp/c=PP-");
135 expect(analyzer.test("corenlp/c=XY-")).toEqual("corenlp/c=XY-");
Akroncff9bac2016-01-25 21:39:38 +0100136 expect(analyzer.test("sgbr/l=")).toEqual("sgbr/l=");
137 expect(analyzer.test("sgbr/lv=")).toEqual("sgbr/lv=");
138 expect(analyzer.test("sgbr/p=")).toEqual("sgbr/p=");
Akronee9ef4a2016-06-03 12:50:08 +0200139 expect(analyzer.test("")).toEqual(undefined);
140 expect(analyzer.test("abcdecnx/")).toEqual("abcdecnx/");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000141 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000142 });
143
Nils Diewald19ccee92014-12-08 11:30:08 +0000144
Nils Diewald7c8ced22015-04-15 19:21:00 +0000145 describe('KorAP.Hint', function () {
146 KorAP.hintArray = {
Akron02360e42016-06-07 13:41:12 +0200147 "-" : [
148 ["Base Annotation", "base/s=", "Structure"],
149 ["CoreNLP", "corenlp/", "Constituency, Named Entities, Part-of-Speech"]
150 ],
Nils Diewald7c8ced22015-04-15 19:21:00 +0000151 "corenlp/" : [
152 ["Named Entity", "ne=" , "Combined"],
153 ["Named Entity", "ne_dewac_175m_600=" , "ne_dewac_175m_600"],
154 ["Named Entity", "ne_hgc_175m_600=", "ne_hgc_175m_600"]
155 ]
156 };
Nils Diewald19ccee92014-12-08 11:30:08 +0000157
Nils Diewald7c8ced22015-04-15 19:21:00 +0000158 beforeEach(function () {
159 input = document.createElement("input");
160 input.setAttribute("type", "text");
161 input.setAttribute("value", "abcdefghijklmno");
162 input.style.position = 'absolute';
163 input.style.top = "20px";
164 input.style.left = "30px";
165 input.focus();
166 input.selectionStart = 5;
167 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000168
Nils Diewald7c8ced22015-04-15 19:21:00 +0000169 it('should be initializable', function () {
170 // Supports: context, searchField
171 var hint = hintClass.create({
172 inputField : input
173 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000174
Nils Diewald7c8ced22015-04-15 19:21:00 +0000175 expect(hint).toBeTruthy();
176 });
Akron00cd4d12016-05-31 21:01:11 +0200177
178 it('should alert at char pos', function () {
179 var hint = hintClass.create({
180 inputField : input
181 });
182
183 expect(hint.active()).toBeFalsy();
184
185 expect(hint.alert(4, 'That does not work!')).toBeTruthy();
186
187 expect(hint.active()).toBeTruthy();
188
189 var container = hint.inputField().container();
190 expect(container.firstChild.classList.contains('hint')).toBe(true);
191 expect(container.firstChild.classList.contains('alert')).toBe(true);
192 expect(container.firstChild.textContent).toEqual('That does not work!');
193 expect(hint.inputField().mirrorValue()).toEqual('abcd');
194
195 expect(hint.alert(4, 'That does not work!')).toBeFalsy();
196
197 // Update - meaning: hide alert
198 hint.update();
199
200 expect(hint.alert().active).toBeFalsy();
201
202 expect(hint.active()).toBeFalsy();
Akronee9ef4a2016-06-03 12:50:08 +0200203 });
Akron00cd4d12016-05-31 21:01:11 +0200204
Akronee9ef4a2016-06-03 12:50:08 +0200205 it('should view main menu on default', function () {
206 var hint = hintClass.create({
Akron8eaeb2e2016-08-29 18:26:28 +0200207 inputField : input
Akronee9ef4a2016-06-03 12:50:08 +0200208 });
209
210 expect(hint.active()).toBeFalsy();
211
212 hint.inputField().insert('der Baum corenlp/');
Akronee9ef4a2016-06-03 12:50:08 +0200213
Akron8eaeb2e2016-08-29 18:26:28 +0200214 var cont = hint.inputField().container();
215
216 expect(cont.getElementsByTagName('div').length).toBe(1);
217 expect(cont.getElementsByTagName('ul').length).toBe(0);
218 expect(cont.firstChild).toEqual(cont.firstChild);
219
220 // Show menu, if a relevant context exists
221 // There is a menu for corenlp/
Akron02360e42016-06-07 13:41:12 +0200222 hint.show(false);
223
Akron8eaeb2e2016-08-29 18:26:28 +0200224 expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(1);
225 expect(hint.inputField().container().getElementsByTagName('li').length).toEqual(3);
226
227 // Hide the menu and focus on the input
228 hint.unshow();
229
Akron02360e42016-06-07 13:41:12 +0200230 console.log('1: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>');
231 console.log(hint.inputField().container().innerHTML);
Akronee9ef4a2016-06-03 12:50:08 +0200232
Akron8eaeb2e2016-08-29 18:26:28 +0200233 /*
234
235
236
Akronee9ef4a2016-06-03 12:50:08 +0200237 expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(4);
Akron02360e42016-06-07 13:41:12 +0200238 expect(hint.inputField().container().getElementsByTagName('li').length).toEqual(3);
Akronee9ef4a2016-06-03 12:50:08 +0200239
Akron02360e42016-06-07 13:41:12 +0200240 hint.unshow();
Akronee9ef4a2016-06-03 12:50:08 +0200241 hint.inputField().insert(' hhhh');
242 // show with context
Akron02360e42016-06-07 13:41:12 +0200243 hint.show(false);
244
245 console.log('2: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>');
246 console.log(hint.inputField().container().innerHTML);
Akronee9ef4a2016-06-03 12:50:08 +0200247
248 expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(4);
249 expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(1);
Akron02360e42016-06-07 13:41:12 +0200250 expect(hint.inputField().container().getElementsByTagName('li').length).toEqual(2);
251
Akron8eaeb2e2016-08-29 18:26:28 +0200252
253
254
255
256
Akron02360e42016-06-07 13:41:12 +0200257
258
Akronee9ef4a2016-06-03 12:50:08 +0200259
260 hint.unshow();
261 hint.inputField().insert(' aaaa/');
262
263 // show with context
264 hint.show(true);
265
266 console.log(hint.inputField().container().outerHTML);
267
268 expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(4);
269 expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(1);
Akron02360e42016-06-07 13:41:12 +0200270*/
Akron00cd4d12016-05-31 21:01:11 +0200271 });
Akron02360e42016-06-07 13:41:12 +0200272
273 xit('should remove all menus on escape');
Nils Diewald19ccee92014-12-08 11:30:08 +0000274 });
275
Nils Diewald7c8ced22015-04-15 19:21:00 +0000276 describe('KorAP.HintMenuItem', function () {
277 it('should be initializable', function () {
278 expect(
279 function() { menuItemClass.create([]) }
280 ).toThrow(new Error("Missing parameters"));
Nils Diewald19ccee92014-12-08 11:30:08 +0000281
Nils Diewald7c8ced22015-04-15 19:21:00 +0000282 expect(
283 function() { menuItemClass.create(['CoreNLP']) }
284 ).toThrow(new Error("Missing parameters"));
Nils Diewald19ccee92014-12-08 11:30:08 +0000285
Nils Diewald7c8ced22015-04-15 19:21:00 +0000286 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
287 expect(menuItem.name()).toEqual('CoreNLP');
288 expect(menuItem.action()).toEqual('corenlp/');
289 expect(menuItem.desc()).toBeUndefined();
Nils Diewald19ccee92014-12-08 11:30:08 +0000290
Nils Diewald7c8ced22015-04-15 19:21:00 +0000291 menuItem = menuItemClass.create(
292 ['CoreNLP', 'corenlp/', 'It\'s funny']
293 );
294 expect(menuItem.name()).toEqual('CoreNLP');
295 expect(menuItem.action()).toEqual('corenlp/');
296 expect(menuItem.desc()).not.toBeUndefined();
297 expect(menuItem.desc()).toEqual('It\'s funny');
298 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000299
Nils Diewald7c8ced22015-04-15 19:21:00 +0000300 it('should have an element', function () {
301 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
302 expect(menuItem.element()).not.toBe(undefined);
303 expect(menuItem.element().nodeName).toEqual("LI");
Nils Diewald19ccee92014-12-08 11:30:08 +0000304
Nils Diewald7c8ced22015-04-15 19:21:00 +0000305 var title = menuItem.element().firstChild;
306 expect(title.nodeName).toEqual("SPAN");
307 expect(title.firstChild.nodeType).toEqual(3);
308 expect(title.firstChild.nodeValue).toEqual("CoreNLP");
309 expect(menuItem.element().childNodes[0]).not.toBe(undefined);
310 expect(menuItem.element().childNodes[1]).toBe(undefined);
Nils Diewald19ccee92014-12-08 11:30:08 +0000311
Nils Diewald7c8ced22015-04-15 19:21:00 +0000312 menuItem = menuItemClass.create(
313 ['CoreNLP', 'corenlp/', 'my DescRiption']
314 );
315 expect(menuItem.element()).not.toBe(undefined);
316 expect(menuItem.element().nodeName).toEqual("LI");
Nils Diewald19ccee92014-12-08 11:30:08 +0000317
Nils Diewald7c8ced22015-04-15 19:21:00 +0000318 title = menuItem.element().firstChild;
319 expect(title.nodeName).toEqual("SPAN");
320 expect(title.firstChild.nodeType).toEqual(3); // TextNode
321 expect(title.firstChild.nodeValue).toEqual("CoreNLP");
Nils Diewald19ccee92014-12-08 11:30:08 +0000322
Nils Diewald7c8ced22015-04-15 19:21:00 +0000323 expect(menuItem.element().childNodes[0]).not.toBe(undefined);
324 expect(menuItem.element().childNodes[1]).not.toBe(undefined);
Nils Diewald19ccee92014-12-08 11:30:08 +0000325
Nils Diewald7c8ced22015-04-15 19:21:00 +0000326 var desc = menuItem.element().lastChild;
327 expect(desc.nodeName).toEqual("SPAN");
328 expect(desc.firstChild.nodeType).toEqual(3); // TextNode
329 expect(desc.firstChild.nodeValue).toEqual("my DescRiption");
330 });
Nils Diewald1c546922015-04-13 01:56:19 +0000331
Nils Diewald19ccee92014-12-08 11:30:08 +0000332
Nils Diewald7c8ced22015-04-15 19:21:00 +0000333 it('should be activatable and deactivateable by class', function () {
334 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
335 expect(menuItem.active()).toBe(false);
336 expect(menuItem.element().getAttribute("class")).toBe(null);
337 menuItem.active(true);
338 expect(menuItem.active()).toBe(true);
339 expect(menuItem.element().getAttribute("class")).toEqual("active");
340 menuItem.active(false); // Is active
341 expect(menuItem.active()).toBe(false);
342 expect(menuItem.element().getAttribute("class")).toEqual("");
343 menuItem.active(true);
344 expect(menuItem.active()).toBe(true);
345 expect(menuItem.element().getAttribute("class")).toEqual("active");
Nils Diewald19ccee92014-12-08 11:30:08 +0000346
Nils Diewald7c8ced22015-04-15 19:21:00 +0000347 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
348 expect(menuItem.active()).toBe(false);
349 expect(menuItem.element().getAttribute("class")).toBe(null);
350 menuItem.active(false); // Is not active
351 expect(menuItem.active()).toBe(false);
352 expect(menuItem.element().getAttribute("class")).toBe(null);
353 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000354
Nils Diewald7c8ced22015-04-15 19:21:00 +0000355 it('should be set to boundary', function () {
356 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
357 expect(menuItem.active()).toBe(false);
358 expect(menuItem.element().getAttribute("class")).toBe(null);
Nils Diewald19ccee92014-12-08 11:30:08 +0000359
Nils Diewald7c8ced22015-04-15 19:21:00 +0000360 // Set active
361 menuItem.active(true);
362 expect(menuItem.active()).toBe(true);
363 expect(menuItem.noMore()).toBe(false);
364 expect(menuItem.element().getAttribute("class")).toEqual("active");
Nils Diewald19ccee92014-12-08 11:30:08 +0000365
Nils Diewald7c8ced22015-04-15 19:21:00 +0000366 // Set no more
367 menuItem.noMore(true);
368 expect(menuItem.active()).toBe(true);
369 expect(menuItem.noMore()).toBe(true);
370 expect(menuItem.element().getAttribute("class")).toEqual("active no-more");
Nils Diewald1c546922015-04-13 01:56:19 +0000371
Nils Diewald7c8ced22015-04-15 19:21:00 +0000372 // No no more
373 menuItem.noMore(false);
374 expect(menuItem.active()).toBe(true);
375 expect(menuItem.noMore()).toBe(false);
376 expect(menuItem.element().getAttribute("class")).toEqual("active");
Nils Diewald1c546922015-04-13 01:56:19 +0000377
Nils Diewald7c8ced22015-04-15 19:21:00 +0000378 // Set no more, deactivate
379 menuItem.noMore(true);
380 menuItem.active(false);
381 expect(menuItem.active()).toBe(false);
382 expect(menuItem.noMore()).toBe(true);
383 expect(menuItem.element().getAttribute("class")).toEqual("no-more");
Nils Diewald19ccee92014-12-08 11:30:08 +0000384
Nils Diewald7c8ced22015-04-15 19:21:00 +0000385 // Set active
386 menuItem.active(true);
387 expect(menuItem.active()).toBe(true);
388 expect(menuItem.noMore()).toBe(true);
389 expect(menuItem.element().getAttribute("class")).toEqual("no-more active");
390 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000391
Nils Diewald7c8ced22015-04-15 19:21:00 +0000392 it('should be highlightable', function () {
393 // Highlight in the middle
394 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
395 menuItem.highlight("ren");
396 expect(menuItem.element().innerHTML).toEqual("<span>Co<mark>reN</mark>LP</span>");
Nils Diewald19ccee92014-12-08 11:30:08 +0000397
Nils Diewald7c8ced22015-04-15 19:21:00 +0000398 menuItem.lowlight();
399 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
Nils Diewald19ccee92014-12-08 11:30:08 +0000400
Nils Diewald7c8ced22015-04-15 19:21:00 +0000401 // Starting highlight
402 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
403 menuItem.highlight("cor");
404 expect(menuItem.element().innerHTML).toEqual("<span><mark>Cor</mark>eNLP</span>");
Nils Diewald19ccee92014-12-08 11:30:08 +0000405
Nils Diewald7c8ced22015-04-15 19:21:00 +0000406 menuItem.lowlight();
407 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
408
409 // Starting highlight - short
410 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
411 menuItem.highlight("c");
412 expect(menuItem.element().innerHTML).toEqual("<span><mark>C</mark>oreNLP</span>");
413
414 menuItem.lowlight();
415 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
416
417 // Highlight at the end
418 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
419 menuItem.highlight("nlp");
420 expect(menuItem.element().innerHTML).toEqual("<span>Core<mark>NLP</mark></span>");
421
422 menuItem.lowlight();
423 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
424
425 // Highlight at the end - short
426 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
427 menuItem.highlight("p");
428 expect(menuItem.element().innerHTML).toEqual("<span>CoreNL<mark>P</mark></span>");
429
430 menuItem.lowlight();
431 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
432
433 // No highlight
434 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
435 menuItem.highlight("xp");
436 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
437
438 menuItem.lowlight();
439 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
440
441 // Highlight in the middle - first
442 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
443
444 menuItem.highlight("ren");
445 expect(menuItem.element().innerHTML).toEqual("<span>Co<mark>reN</mark>LP</span><span class=\"desc\">This is my Example</span>");
446
447 menuItem.lowlight();
448 expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Example</span>');
449
450 // Highlight in the middle - second
451 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
452 menuItem.highlight("ampl");
453 expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Ex<mark>ampl</mark>e</span>');
454
455 menuItem.lowlight();
456 expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Example</span>');
457
458 // Highlight in the middle - both
459 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
460
461 menuItem.highlight("e");
462 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>');
463
464 menuItem.lowlight();
465 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>");
466
467 // Highlight in the end - second
468 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
469 menuItem.highlight("le");
470 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Examp<mark>le</mark></span>");
471
472 menuItem.lowlight();
473 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>");
474
475 // Highlight at the beginning - second
476 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
477 menuItem.highlight("this");
478 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\"><mark>This</mark> is my Example</span>");
479
480 menuItem.lowlight();
481 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>");
Akron6ed13992016-05-23 18:06:05 +0200482
Nils Diewald7c8ced22015-04-15 19:21:00 +0000483 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000484 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000485
Nils Diewald7c8ced22015-04-15 19:21:00 +0000486 describe('KorAP.HintMenu', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000487 var list = [
488 ["Constituency", "c=", "Example 1"],
489 ["Lemma", "l="],
490 ["Morphology", "m=", "Example 2"],
491 ["Part-of-Speech", "p="],
492 ["Syntax", "syn="]
493 ];
Nils Diewald19ccee92014-12-08 11:30:08 +0000494
Nils Diewald7c8ced22015-04-15 19:21:00 +0000495 it('should be initializable', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000496 var menu = menuClass.create(null, "cnx/", list);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000497 expect(menu.element().nodeName).toEqual('UL');
498 expect(menu.element().style.opacity).toEqual("0");
Nils Diewald19ccee92014-12-08 11:30:08 +0000499
Nils Diewald7c8ced22015-04-15 19:21:00 +0000500 menu.limit(8);
Nils Diewald19ccee92014-12-08 11:30:08 +0000501
Nils Diewald7c8ced22015-04-15 19:21:00 +0000502 // view
503 menu.show();
Akron6ed13992016-05-23 18:06:05 +0200504 expect(menu.prefix()).toBe('');
Nils Diewald19ccee92014-12-08 11:30:08 +0000505
Nils Diewald7c8ced22015-04-15 19:21:00 +0000506 // First element in list
507 expect(menu.item(0).active()).toBe(true);
508 expect(menu.item(0).noMore()).toBe(true);
509
510 // Middle element in list
511 expect(menu.item(2).active()).toBe(false);
512 expect(menu.item(2).noMore()).toBe(false);
Nils Diewald19ccee92014-12-08 11:30:08 +0000513
Nils Diewald7c8ced22015-04-15 19:21:00 +0000514 // Last element in list
515 expect(menu.item(menu.length() - 1).active()).toBe(false);
516 expect(menu.item(menu.length() - 1).noMore()).toBe(true);
Akron6ed13992016-05-23 18:06:05 +0200517
518 expect(menu.shownItem(0).active()).toBeTruthy();
519 expect(menu.shownItem(0).lcField()).toEqual(' constituency example 1');
520 expect(menu.shownItem(1).lcField()).toEqual(' lemma');
521 expect(menu.shownItem(2).lcField()).toEqual(' morphology example 2');
522
523 menu.next();
524 expect(menu.shownItem(1).active()).toBeTruthy();
525
526 menu.next();
527 expect(menu.shownItem(2).active()).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000528 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000529 });
530});