blob: 940ba8fb5919b77e017049eaa5f6df743e0f1257 [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 = {
Akron02360e42016-06-07 13:41:12 +0200148 "-" : [
149 ["Base Annotation", "base/s=", "Structure"],
150 ["CoreNLP", "corenlp/", "Constituency, Named Entities, Part-of-Speech"]
151 ],
Nils Diewald7c8ced22015-04-15 19:21:00 +0000152 "corenlp/" : [
153 ["Named Entity", "ne=" , "Combined"],
154 ["Named Entity", "ne_dewac_175m_600=" , "ne_dewac_175m_600"],
155 ["Named Entity", "ne_hgc_175m_600=", "ne_hgc_175m_600"]
156 ]
157 };
Nils Diewald19ccee92014-12-08 11:30:08 +0000158
Nils Diewald7c8ced22015-04-15 19:21:00 +0000159 beforeEach(function () {
160 input = document.createElement("input");
161 input.setAttribute("type", "text");
162 input.setAttribute("value", "abcdefghijklmno");
163 input.style.position = 'absolute';
164 input.style.top = "20px";
165 input.style.left = "30px";
166 input.focus();
167 input.selectionStart = 5;
168 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000169
Nils Diewald7c8ced22015-04-15 19:21:00 +0000170 it('should be initializable', function () {
171 // Supports: context, searchField
172 var hint = hintClass.create({
173 inputField : input
174 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000175
Nils Diewald7c8ced22015-04-15 19:21:00 +0000176 expect(hint).toBeTruthy();
177 });
Akron00cd4d12016-05-31 21:01:11 +0200178
179 it('should alert at char pos', function () {
180 var hint = hintClass.create({
181 inputField : input
182 });
183
184 expect(hint.active()).toBeFalsy();
185
186 expect(hint.alert(4, 'That does not work!')).toBeTruthy();
187
188 expect(hint.active()).toBeTruthy();
189
190 var container = hint.inputField().container();
191 expect(container.firstChild.classList.contains('hint')).toBe(true);
192 expect(container.firstChild.classList.contains('alert')).toBe(true);
193 expect(container.firstChild.textContent).toEqual('That does not work!');
194 expect(hint.inputField().mirrorValue()).toEqual('abcd');
195
196 expect(hint.alert(4, 'That does not work!')).toBeFalsy();
197
198 // Update - meaning: hide alert
199 hint.update();
200
201 expect(hint.alert().active).toBeFalsy();
202
203 expect(hint.active()).toBeFalsy();
Akronee9ef4a2016-06-03 12:50:08 +0200204 });
Akron00cd4d12016-05-31 21:01:11 +0200205
Akronee9ef4a2016-06-03 12:50:08 +0200206 it('should view main menu on default', function () {
207 var hint = hintClass.create({
208 inputField : input
209 });
210
211 expect(hint.active()).toBeFalsy();
212
213 hint.inputField().insert('der Baum corenlp/');
214 expect(hint.inputField().container().getElementsByTagName('div').length).toBe(1);
215 expect(hint.inputField().container().getElementsByTagName('ul').length).toBe(0);
216
217 // show with context
218 hint.unshow();
Akron02360e42016-06-07 13:41:12 +0200219 hint.show(false);
220
221 console.log('1: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>');
222 console.log(hint.inputField().container().innerHTML);
Akronee9ef4a2016-06-03 12:50:08 +0200223
224 expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(4);
225 expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(1);
Akron02360e42016-06-07 13:41:12 +0200226 expect(hint.inputField().container().getElementsByTagName('li').length).toEqual(3);
Akronee9ef4a2016-06-03 12:50:08 +0200227
Akron02360e42016-06-07 13:41:12 +0200228 hint.unshow();
Akronee9ef4a2016-06-03 12:50:08 +0200229 hint.inputField().insert(' hhhh');
230 // show with context
Akron02360e42016-06-07 13:41:12 +0200231 hint.show(false);
232
233 console.log('2: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>');
234 console.log(hint.inputField().container().innerHTML);
Akronee9ef4a2016-06-03 12:50:08 +0200235
236 expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(4);
237 expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(1);
Akron02360e42016-06-07 13:41:12 +0200238 expect(hint.inputField().container().getElementsByTagName('li').length).toEqual(2);
239
240/*
241
242
Akronee9ef4a2016-06-03 12:50:08 +0200243
244 hint.unshow();
245 hint.inputField().insert(' aaaa/');
246
247 // show with context
248 hint.show(true);
249
250 console.log(hint.inputField().container().outerHTML);
251
252 expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(4);
253 expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(1);
Akron02360e42016-06-07 13:41:12 +0200254*/
Akron00cd4d12016-05-31 21:01:11 +0200255 });
Akron02360e42016-06-07 13:41:12 +0200256
257 xit('should remove all menus on escape');
Nils Diewald19ccee92014-12-08 11:30:08 +0000258 });
259
Nils Diewald7c8ced22015-04-15 19:21:00 +0000260 describe('KorAP.HintMenuItem', function () {
261 it('should be initializable', function () {
262 expect(
263 function() { menuItemClass.create([]) }
264 ).toThrow(new Error("Missing parameters"));
Nils Diewald19ccee92014-12-08 11:30:08 +0000265
Nils Diewald7c8ced22015-04-15 19:21:00 +0000266 expect(
267 function() { menuItemClass.create(['CoreNLP']) }
268 ).toThrow(new Error("Missing parameters"));
Nils Diewald19ccee92014-12-08 11:30:08 +0000269
Nils Diewald7c8ced22015-04-15 19:21:00 +0000270 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
271 expect(menuItem.name()).toEqual('CoreNLP');
272 expect(menuItem.action()).toEqual('corenlp/');
273 expect(menuItem.desc()).toBeUndefined();
Nils Diewald19ccee92014-12-08 11:30:08 +0000274
Nils Diewald7c8ced22015-04-15 19:21:00 +0000275 menuItem = menuItemClass.create(
276 ['CoreNLP', 'corenlp/', 'It\'s funny']
277 );
278 expect(menuItem.name()).toEqual('CoreNLP');
279 expect(menuItem.action()).toEqual('corenlp/');
280 expect(menuItem.desc()).not.toBeUndefined();
281 expect(menuItem.desc()).toEqual('It\'s funny');
282 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000283
Nils Diewald7c8ced22015-04-15 19:21:00 +0000284 it('should have an element', function () {
285 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
286 expect(menuItem.element()).not.toBe(undefined);
287 expect(menuItem.element().nodeName).toEqual("LI");
Nils Diewald19ccee92014-12-08 11:30:08 +0000288
Nils Diewald7c8ced22015-04-15 19:21:00 +0000289 var title = menuItem.element().firstChild;
290 expect(title.nodeName).toEqual("SPAN");
291 expect(title.firstChild.nodeType).toEqual(3);
292 expect(title.firstChild.nodeValue).toEqual("CoreNLP");
293 expect(menuItem.element().childNodes[0]).not.toBe(undefined);
294 expect(menuItem.element().childNodes[1]).toBe(undefined);
Nils Diewald19ccee92014-12-08 11:30:08 +0000295
Nils Diewald7c8ced22015-04-15 19:21:00 +0000296 menuItem = menuItemClass.create(
297 ['CoreNLP', 'corenlp/', 'my DescRiption']
298 );
299 expect(menuItem.element()).not.toBe(undefined);
300 expect(menuItem.element().nodeName).toEqual("LI");
Nils Diewald19ccee92014-12-08 11:30:08 +0000301
Nils Diewald7c8ced22015-04-15 19:21:00 +0000302 title = menuItem.element().firstChild;
303 expect(title.nodeName).toEqual("SPAN");
304 expect(title.firstChild.nodeType).toEqual(3); // TextNode
305 expect(title.firstChild.nodeValue).toEqual("CoreNLP");
Nils Diewald19ccee92014-12-08 11:30:08 +0000306
Nils Diewald7c8ced22015-04-15 19:21:00 +0000307 expect(menuItem.element().childNodes[0]).not.toBe(undefined);
308 expect(menuItem.element().childNodes[1]).not.toBe(undefined);
Nils Diewald19ccee92014-12-08 11:30:08 +0000309
Nils Diewald7c8ced22015-04-15 19:21:00 +0000310 var desc = menuItem.element().lastChild;
311 expect(desc.nodeName).toEqual("SPAN");
312 expect(desc.firstChild.nodeType).toEqual(3); // TextNode
313 expect(desc.firstChild.nodeValue).toEqual("my DescRiption");
314 });
Nils Diewald1c546922015-04-13 01:56:19 +0000315
Nils Diewald19ccee92014-12-08 11:30:08 +0000316
Nils Diewald7c8ced22015-04-15 19:21:00 +0000317 it('should be activatable and deactivateable by class', function () {
318 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
319 expect(menuItem.active()).toBe(false);
320 expect(menuItem.element().getAttribute("class")).toBe(null);
321 menuItem.active(true);
322 expect(menuItem.active()).toBe(true);
323 expect(menuItem.element().getAttribute("class")).toEqual("active");
324 menuItem.active(false); // Is active
325 expect(menuItem.active()).toBe(false);
326 expect(menuItem.element().getAttribute("class")).toEqual("");
327 menuItem.active(true);
328 expect(menuItem.active()).toBe(true);
329 expect(menuItem.element().getAttribute("class")).toEqual("active");
Nils Diewald19ccee92014-12-08 11:30:08 +0000330
Nils Diewald7c8ced22015-04-15 19:21:00 +0000331 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
332 expect(menuItem.active()).toBe(false);
333 expect(menuItem.element().getAttribute("class")).toBe(null);
334 menuItem.active(false); // Is not active
335 expect(menuItem.active()).toBe(false);
336 expect(menuItem.element().getAttribute("class")).toBe(null);
337 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000338
Nils Diewald7c8ced22015-04-15 19:21:00 +0000339 it('should be set to boundary', function () {
340 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
341 expect(menuItem.active()).toBe(false);
342 expect(menuItem.element().getAttribute("class")).toBe(null);
Nils Diewald19ccee92014-12-08 11:30:08 +0000343
Nils Diewald7c8ced22015-04-15 19:21:00 +0000344 // Set active
345 menuItem.active(true);
346 expect(menuItem.active()).toBe(true);
347 expect(menuItem.noMore()).toBe(false);
348 expect(menuItem.element().getAttribute("class")).toEqual("active");
Nils Diewald19ccee92014-12-08 11:30:08 +0000349
Nils Diewald7c8ced22015-04-15 19:21:00 +0000350 // Set no more
351 menuItem.noMore(true);
352 expect(menuItem.active()).toBe(true);
353 expect(menuItem.noMore()).toBe(true);
354 expect(menuItem.element().getAttribute("class")).toEqual("active no-more");
Nils Diewald1c546922015-04-13 01:56:19 +0000355
Nils Diewald7c8ced22015-04-15 19:21:00 +0000356 // No no more
357 menuItem.noMore(false);
358 expect(menuItem.active()).toBe(true);
359 expect(menuItem.noMore()).toBe(false);
360 expect(menuItem.element().getAttribute("class")).toEqual("active");
Nils Diewald1c546922015-04-13 01:56:19 +0000361
Nils Diewald7c8ced22015-04-15 19:21:00 +0000362 // Set no more, deactivate
363 menuItem.noMore(true);
364 menuItem.active(false);
365 expect(menuItem.active()).toBe(false);
366 expect(menuItem.noMore()).toBe(true);
367 expect(menuItem.element().getAttribute("class")).toEqual("no-more");
Nils Diewald19ccee92014-12-08 11:30:08 +0000368
Nils Diewald7c8ced22015-04-15 19:21:00 +0000369 // Set active
370 menuItem.active(true);
371 expect(menuItem.active()).toBe(true);
372 expect(menuItem.noMore()).toBe(true);
373 expect(menuItem.element().getAttribute("class")).toEqual("no-more active");
374 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000375
Nils Diewald7c8ced22015-04-15 19:21:00 +0000376 it('should be highlightable', function () {
377 // Highlight in the middle
378 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
379 menuItem.highlight("ren");
380 expect(menuItem.element().innerHTML).toEqual("<span>Co<mark>reN</mark>LP</span>");
Nils Diewald19ccee92014-12-08 11:30:08 +0000381
Nils Diewald7c8ced22015-04-15 19:21:00 +0000382 menuItem.lowlight();
383 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
Nils Diewald19ccee92014-12-08 11:30:08 +0000384
Nils Diewald7c8ced22015-04-15 19:21:00 +0000385 // Starting highlight
386 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
387 menuItem.highlight("cor");
388 expect(menuItem.element().innerHTML).toEqual("<span><mark>Cor</mark>eNLP</span>");
Nils Diewald19ccee92014-12-08 11:30:08 +0000389
Nils Diewald7c8ced22015-04-15 19:21:00 +0000390 menuItem.lowlight();
391 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
392
393 // Starting highlight - short
394 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
395 menuItem.highlight("c");
396 expect(menuItem.element().innerHTML).toEqual("<span><mark>C</mark>oreNLP</span>");
397
398 menuItem.lowlight();
399 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
400
401 // Highlight at the end
402 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
403 menuItem.highlight("nlp");
404 expect(menuItem.element().innerHTML).toEqual("<span>Core<mark>NLP</mark></span>");
405
406 menuItem.lowlight();
407 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
408
409 // Highlight at the end - short
410 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
411 menuItem.highlight("p");
412 expect(menuItem.element().innerHTML).toEqual("<span>CoreNL<mark>P</mark></span>");
413
414 menuItem.lowlight();
415 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
416
417 // No highlight
418 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
419 menuItem.highlight("xp");
420 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
421
422 menuItem.lowlight();
423 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
424
425 // Highlight in the middle - first
426 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
427
428 menuItem.highlight("ren");
429 expect(menuItem.element().innerHTML).toEqual("<span>Co<mark>reN</mark>LP</span><span class=\"desc\">This is my Example</span>");
430
431 menuItem.lowlight();
432 expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Example</span>');
433
434 // Highlight in the middle - second
435 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
436 menuItem.highlight("ampl");
437 expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Ex<mark>ampl</mark>e</span>');
438
439 menuItem.lowlight();
440 expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Example</span>');
441
442 // Highlight in the middle - both
443 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
444
445 menuItem.highlight("e");
446 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>');
447
448 menuItem.lowlight();
449 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>");
450
451 // Highlight in the end - second
452 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
453 menuItem.highlight("le");
454 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Examp<mark>le</mark></span>");
455
456 menuItem.lowlight();
457 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>");
458
459 // Highlight at the beginning - second
460 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
461 menuItem.highlight("this");
462 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\"><mark>This</mark> is my Example</span>");
463
464 menuItem.lowlight();
465 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>");
Akron6ed13992016-05-23 18:06:05 +0200466
Nils Diewald7c8ced22015-04-15 19:21:00 +0000467 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000468 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000469
Nils Diewald7c8ced22015-04-15 19:21:00 +0000470 describe('KorAP.HintMenu', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000471 var list = [
472 ["Constituency", "c=", "Example 1"],
473 ["Lemma", "l="],
474 ["Morphology", "m=", "Example 2"],
475 ["Part-of-Speech", "p="],
476 ["Syntax", "syn="]
477 ];
Nils Diewald19ccee92014-12-08 11:30:08 +0000478
Nils Diewald7c8ced22015-04-15 19:21:00 +0000479 it('should be initializable', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000480 var menu = menuClass.create(null, "cnx/", list);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000481 expect(menu.element().nodeName).toEqual('UL');
482 expect(menu.element().style.opacity).toEqual("0");
Nils Diewald19ccee92014-12-08 11:30:08 +0000483
Nils Diewald7c8ced22015-04-15 19:21:00 +0000484 menu.limit(8);
Nils Diewald19ccee92014-12-08 11:30:08 +0000485
Nils Diewald7c8ced22015-04-15 19:21:00 +0000486 // view
487 menu.show();
Akron6ed13992016-05-23 18:06:05 +0200488 expect(menu.prefix()).toBe('');
Nils Diewald19ccee92014-12-08 11:30:08 +0000489
Nils Diewald7c8ced22015-04-15 19:21:00 +0000490 // First element in list
491 expect(menu.item(0).active()).toBe(true);
492 expect(menu.item(0).noMore()).toBe(true);
493
494 // Middle element in list
495 expect(menu.item(2).active()).toBe(false);
496 expect(menu.item(2).noMore()).toBe(false);
Nils Diewald19ccee92014-12-08 11:30:08 +0000497
Nils Diewald7c8ced22015-04-15 19:21:00 +0000498 // Last element in list
499 expect(menu.item(menu.length() - 1).active()).toBe(false);
500 expect(menu.item(menu.length() - 1).noMore()).toBe(true);
Akron6ed13992016-05-23 18:06:05 +0200501
502 expect(menu.shownItem(0).active()).toBeTruthy();
503 expect(menu.shownItem(0).lcField()).toEqual(' constituency example 1');
504 expect(menu.shownItem(1).lcField()).toEqual(' lemma');
505 expect(menu.shownItem(2).lcField()).toEqual(' morphology example 2');
506
507 menu.next();
508 expect(menu.shownItem(1).active()).toBeTruthy();
509
510 menu.next();
511 expect(menu.shownItem(2).active()).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000512 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000513 });
514});