blob: 667ac7add9f34b069a27de9e99e6682ec6337f26 [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);
Akron65c74352016-09-02 17:23:39 +0200226
Akron8eaeb2e2016-08-29 18:26:28 +0200227 // Hide the menu and focus on the input
228 hint.unshow();
Akron65c74352016-09-02 17:23:39 +0200229
230 expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(1);
231 expect(hint.inputField().container().getElementsByTagName('li').length).toEqual(0);
Akronee9ef4a2016-06-03 12:50:08 +0200232
Akron02360e42016-06-07 13:41:12 +0200233 hint.unshow();
Akron65c74352016-09-02 17:23:39 +0200234
Akronee9ef4a2016-06-03 12:50:08 +0200235 hint.inputField().insert(' hhhh');
Akron65c74352016-09-02 17:23:39 +0200236
Akronee9ef4a2016-06-03 12:50:08 +0200237 // show with context
Akron02360e42016-06-07 13:41:12 +0200238 hint.show(false);
Akron65c74352016-09-02 17:23:39 +0200239
Akronee9ef4a2016-06-03 12:50:08 +0200240 expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(4);
241 expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(1);
Akron02360e42016-06-07 13:41:12 +0200242 expect(hint.inputField().container().getElementsByTagName('li').length).toEqual(2);
243
Akronee9ef4a2016-06-03 12:50:08 +0200244 hint.unshow();
245 hint.inputField().insert(' aaaa/');
246
247 // show with context
248 hint.show(true);
249
Akronee9ef4a2016-06-03 12:50:08 +0200250 expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(4);
251 expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(1);
Akron00cd4d12016-05-31 21:01:11 +0200252 });
Akron65c74352016-09-02 17:23:39 +0200253
Akron02360e42016-06-07 13:41:12 +0200254 xit('should remove all menus on escape');
Nils Diewald19ccee92014-12-08 11:30:08 +0000255 });
256
Akron65c74352016-09-02 17:23:39 +0200257
258
Nils Diewald7c8ced22015-04-15 19:21:00 +0000259 describe('KorAP.HintMenuItem', function () {
260 it('should be initializable', function () {
261 expect(
262 function() { menuItemClass.create([]) }
263 ).toThrow(new Error("Missing parameters"));
Nils Diewald19ccee92014-12-08 11:30:08 +0000264
Nils Diewald7c8ced22015-04-15 19:21:00 +0000265 expect(
266 function() { menuItemClass.create(['CoreNLP']) }
267 ).toThrow(new Error("Missing parameters"));
Nils Diewald19ccee92014-12-08 11:30:08 +0000268
Nils Diewald7c8ced22015-04-15 19:21:00 +0000269 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
270 expect(menuItem.name()).toEqual('CoreNLP');
271 expect(menuItem.action()).toEqual('corenlp/');
272 expect(menuItem.desc()).toBeUndefined();
Nils Diewald19ccee92014-12-08 11:30:08 +0000273
Nils Diewald7c8ced22015-04-15 19:21:00 +0000274 menuItem = menuItemClass.create(
275 ['CoreNLP', 'corenlp/', 'It\'s funny']
276 );
277 expect(menuItem.name()).toEqual('CoreNLP');
278 expect(menuItem.action()).toEqual('corenlp/');
279 expect(menuItem.desc()).not.toBeUndefined();
280 expect(menuItem.desc()).toEqual('It\'s funny');
281 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000282
Nils Diewald7c8ced22015-04-15 19:21:00 +0000283 it('should have an element', function () {
284 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
285 expect(menuItem.element()).not.toBe(undefined);
286 expect(menuItem.element().nodeName).toEqual("LI");
Nils Diewald19ccee92014-12-08 11:30:08 +0000287
Nils Diewald7c8ced22015-04-15 19:21:00 +0000288 var title = menuItem.element().firstChild;
289 expect(title.nodeName).toEqual("SPAN");
290 expect(title.firstChild.nodeType).toEqual(3);
291 expect(title.firstChild.nodeValue).toEqual("CoreNLP");
292 expect(menuItem.element().childNodes[0]).not.toBe(undefined);
293 expect(menuItem.element().childNodes[1]).toBe(undefined);
Nils Diewald19ccee92014-12-08 11:30:08 +0000294
Nils Diewald7c8ced22015-04-15 19:21:00 +0000295 menuItem = menuItemClass.create(
296 ['CoreNLP', 'corenlp/', 'my DescRiption']
297 );
298 expect(menuItem.element()).not.toBe(undefined);
299 expect(menuItem.element().nodeName).toEqual("LI");
Nils Diewald19ccee92014-12-08 11:30:08 +0000300
Nils Diewald7c8ced22015-04-15 19:21:00 +0000301 title = menuItem.element().firstChild;
302 expect(title.nodeName).toEqual("SPAN");
303 expect(title.firstChild.nodeType).toEqual(3); // TextNode
304 expect(title.firstChild.nodeValue).toEqual("CoreNLP");
Nils Diewald19ccee92014-12-08 11:30:08 +0000305
Nils Diewald7c8ced22015-04-15 19:21:00 +0000306 expect(menuItem.element().childNodes[0]).not.toBe(undefined);
307 expect(menuItem.element().childNodes[1]).not.toBe(undefined);
Nils Diewald19ccee92014-12-08 11:30:08 +0000308
Nils Diewald7c8ced22015-04-15 19:21:00 +0000309 var desc = menuItem.element().lastChild;
310 expect(desc.nodeName).toEqual("SPAN");
311 expect(desc.firstChild.nodeType).toEqual(3); // TextNode
312 expect(desc.firstChild.nodeValue).toEqual("my DescRiption");
313 });
Nils Diewald1c546922015-04-13 01:56:19 +0000314
Nils Diewald19ccee92014-12-08 11:30:08 +0000315
Nils Diewald7c8ced22015-04-15 19:21:00 +0000316 it('should be activatable and deactivateable by class', function () {
317 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
318 expect(menuItem.active()).toBe(false);
319 expect(menuItem.element().getAttribute("class")).toBe(null);
320 menuItem.active(true);
321 expect(menuItem.active()).toBe(true);
322 expect(menuItem.element().getAttribute("class")).toEqual("active");
323 menuItem.active(false); // Is active
324 expect(menuItem.active()).toBe(false);
325 expect(menuItem.element().getAttribute("class")).toEqual("");
326 menuItem.active(true);
327 expect(menuItem.active()).toBe(true);
328 expect(menuItem.element().getAttribute("class")).toEqual("active");
Nils Diewald19ccee92014-12-08 11:30:08 +0000329
Nils Diewald7c8ced22015-04-15 19:21:00 +0000330 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
331 expect(menuItem.active()).toBe(false);
332 expect(menuItem.element().getAttribute("class")).toBe(null);
333 menuItem.active(false); // Is not active
334 expect(menuItem.active()).toBe(false);
335 expect(menuItem.element().getAttribute("class")).toBe(null);
336 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000337
Nils Diewald7c8ced22015-04-15 19:21:00 +0000338 it('should be set to boundary', function () {
339 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
340 expect(menuItem.active()).toBe(false);
341 expect(menuItem.element().getAttribute("class")).toBe(null);
Nils Diewald19ccee92014-12-08 11:30:08 +0000342
Nils Diewald7c8ced22015-04-15 19:21:00 +0000343 // Set active
344 menuItem.active(true);
345 expect(menuItem.active()).toBe(true);
346 expect(menuItem.noMore()).toBe(false);
347 expect(menuItem.element().getAttribute("class")).toEqual("active");
Nils Diewald19ccee92014-12-08 11:30:08 +0000348
Nils Diewald7c8ced22015-04-15 19:21:00 +0000349 // Set no more
350 menuItem.noMore(true);
351 expect(menuItem.active()).toBe(true);
352 expect(menuItem.noMore()).toBe(true);
353 expect(menuItem.element().getAttribute("class")).toEqual("active no-more");
Nils Diewald1c546922015-04-13 01:56:19 +0000354
Nils Diewald7c8ced22015-04-15 19:21:00 +0000355 // No no more
356 menuItem.noMore(false);
357 expect(menuItem.active()).toBe(true);
358 expect(menuItem.noMore()).toBe(false);
359 expect(menuItem.element().getAttribute("class")).toEqual("active");
Nils Diewald1c546922015-04-13 01:56:19 +0000360
Nils Diewald7c8ced22015-04-15 19:21:00 +0000361 // Set no more, deactivate
362 menuItem.noMore(true);
363 menuItem.active(false);
364 expect(menuItem.active()).toBe(false);
365 expect(menuItem.noMore()).toBe(true);
366 expect(menuItem.element().getAttribute("class")).toEqual("no-more");
Nils Diewald19ccee92014-12-08 11:30:08 +0000367
Nils Diewald7c8ced22015-04-15 19:21:00 +0000368 // Set active
369 menuItem.active(true);
370 expect(menuItem.active()).toBe(true);
371 expect(menuItem.noMore()).toBe(true);
372 expect(menuItem.element().getAttribute("class")).toEqual("no-more active");
373 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000374
Nils Diewald7c8ced22015-04-15 19:21:00 +0000375 it('should be highlightable', function () {
376 // Highlight in the middle
377 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
378 menuItem.highlight("ren");
379 expect(menuItem.element().innerHTML).toEqual("<span>Co<mark>reN</mark>LP</span>");
Nils Diewald19ccee92014-12-08 11:30:08 +0000380
Nils Diewald7c8ced22015-04-15 19:21:00 +0000381 menuItem.lowlight();
382 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
Nils Diewald19ccee92014-12-08 11:30:08 +0000383
Nils Diewald7c8ced22015-04-15 19:21:00 +0000384 // Starting highlight
385 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
386 menuItem.highlight("cor");
387 expect(menuItem.element().innerHTML).toEqual("<span><mark>Cor</mark>eNLP</span>");
Nils Diewald19ccee92014-12-08 11:30:08 +0000388
Nils Diewald7c8ced22015-04-15 19:21:00 +0000389 menuItem.lowlight();
390 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
391
392 // Starting highlight - short
393 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
394 menuItem.highlight("c");
395 expect(menuItem.element().innerHTML).toEqual("<span><mark>C</mark>oreNLP</span>");
396
397 menuItem.lowlight();
398 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
399
400 // Highlight at the end
401 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
402 menuItem.highlight("nlp");
403 expect(menuItem.element().innerHTML).toEqual("<span>Core<mark>NLP</mark></span>");
404
405 menuItem.lowlight();
406 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
407
408 // Highlight at the end - short
409 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
410 menuItem.highlight("p");
411 expect(menuItem.element().innerHTML).toEqual("<span>CoreNL<mark>P</mark></span>");
412
413 menuItem.lowlight();
414 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
415
416 // No highlight
417 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
418 menuItem.highlight("xp");
419 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
420
421 menuItem.lowlight();
422 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
423
424 // Highlight in the middle - first
425 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
426
427 menuItem.highlight("ren");
428 expect(menuItem.element().innerHTML).toEqual("<span>Co<mark>reN</mark>LP</span><span class=\"desc\">This is my Example</span>");
429
430 menuItem.lowlight();
431 expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Example</span>');
432
433 // Highlight in the middle - second
434 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
435 menuItem.highlight("ampl");
436 expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Ex<mark>ampl</mark>e</span>');
437
438 menuItem.lowlight();
439 expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Example</span>');
440
441 // Highlight in the middle - both
442 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
443
444 menuItem.highlight("e");
445 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>');
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 end - second
451 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
452 menuItem.highlight("le");
453 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Examp<mark>le</mark></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 at the beginning - second
459 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
460 menuItem.highlight("this");
461 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\"><mark>This</mark> is my Example</span>");
462
463 menuItem.lowlight();
464 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>");
Akron6ed13992016-05-23 18:06:05 +0200465
Nils Diewald7c8ced22015-04-15 19:21:00 +0000466 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000467 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000468
Nils Diewald7c8ced22015-04-15 19:21:00 +0000469 describe('KorAP.HintMenu', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000470 var list = [
471 ["Constituency", "c=", "Example 1"],
472 ["Lemma", "l="],
473 ["Morphology", "m=", "Example 2"],
474 ["Part-of-Speech", "p="],
475 ["Syntax", "syn="]
476 ];
Nils Diewald19ccee92014-12-08 11:30:08 +0000477
Nils Diewald7c8ced22015-04-15 19:21:00 +0000478 it('should be initializable', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000479 var menu = menuClass.create(null, "cnx/", list);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000480 expect(menu.element().nodeName).toEqual('UL');
Akron65c74352016-09-02 17:23:39 +0200481 // expect(menu.element().style.opacity).toEqual("0");
Nils Diewald19ccee92014-12-08 11:30:08 +0000482
Nils Diewald7c8ced22015-04-15 19:21:00 +0000483 menu.limit(8);
Nils Diewald19ccee92014-12-08 11:30:08 +0000484
Nils Diewald7c8ced22015-04-15 19:21:00 +0000485 // view
486 menu.show();
Akron6ed13992016-05-23 18:06:05 +0200487 expect(menu.prefix()).toBe('');
Nils Diewald19ccee92014-12-08 11:30:08 +0000488
Nils Diewald7c8ced22015-04-15 19:21:00 +0000489 // First element in list
490 expect(menu.item(0).active()).toBe(true);
491 expect(menu.item(0).noMore()).toBe(true);
492
493 // Middle element in list
494 expect(menu.item(2).active()).toBe(false);
495 expect(menu.item(2).noMore()).toBe(false);
Nils Diewald19ccee92014-12-08 11:30:08 +0000496
Nils Diewald7c8ced22015-04-15 19:21:00 +0000497 // Last element in list
498 expect(menu.item(menu.length() - 1).active()).toBe(false);
499 expect(menu.item(menu.length() - 1).noMore()).toBe(true);
Akron6ed13992016-05-23 18:06:05 +0200500
501 expect(menu.shownItem(0).active()).toBeTruthy();
502 expect(menu.shownItem(0).lcField()).toEqual(' constituency example 1');
503 expect(menu.shownItem(1).lcField()).toEqual(' lemma');
504 expect(menu.shownItem(2).lcField()).toEqual(' morphology example 2');
505
506 menu.next();
507 expect(menu.shownItem(1).active()).toBeTruthy();
508
509 menu.next();
510 expect(menu.shownItem(2).active()).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000511 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000512 });
513});