blob: 90cccb36e9729eab68deefd469024db3b813ebe0 [file] [log] [blame]
Akronfac16472018-07-26 16:47:21 +02001define(['hint', 'hint/input', 'hint/contextanalyzer', 'hint/menu', 'hint/item'], function (hintClass, inputClass, contextClass, menuClass, menuItemClass) {
Nils Diewald19ccee92014-12-08 11:30:08 +00002
Akronfac16472018-07-26 16:47:21 +02003 function emitKeyboardEvent (element, type, keyCode) {
4 // event type : keydown, keyup, keypress
5 // http://stackoverflow.com/questions/596481/simulate-javascript-key-events
6 // http://stackoverflow.com/questions/961532/firing-a-keyboard-event-in-javascript
7 var keyboardEvent = document.createEvent("KeyboardEvent");
8 var initMethod = typeof keyboardEvent.initKeyboardEvent !== 'undefined' ?
9 "initKeyboardEvent" : "initKeyEvent";
10 keyboardEvent[initMethod](
11 type,
12 true, // bubbles
13 true, // cancelable
14 window, // viewArg: should be window
15 false, // ctrlKeyArg
16 false, // altKeyArg
17 false, // shiftKeyArg
18 false, // metaKeyArg
19 keyCode, // keyCodeArg : unsigned long the virtual key code, else 0
20 0 // charCodeArgs : unsigned long the Unicode character
21 // associated with the depressed key, else 0
22 );
23 element.dispatchEvent(keyboardEvent);
24 };
Nils Diewald19ccee92014-12-08 11:30:08 +000025
Akronfac16472018-07-26 16:47:21 +020026 var afterAllFunc = function () {
27 try {
28 var mirrors = document.querySelectorAll(".hint.mirror");
29 for (var i in mirrors) {
30 mirrors[i].parentNode.removeChild(mirrors[i])
31 };
32 }
33 catch (e) {};
34
35 var body = document.body;
36 for (var i in body.children) {
37 if (body.children[i].nodeType && body.children[i].nodeType === 1) {
38 if (!body.children[i].classList.contains("jasmine_html-reporter")) {
39 body.removeChild(body.children[i]);
40 };
41 };
42 };
43 KorAP.API.getMatchInfo = undefined;
44 KorAP.context = undefined;
45 // KorAP.annotationHelper = undefined;
46 };
47
48 var beforeAllFunc = function () {
49 KorAP.annotationHelper = KorAP.annotationHelper || {};
50 KorAP.annotationHelper["-"] = [
51 ["Base Annotation", "base/s=", "Structure"],
52 ["CoreNLP", "corenlp/", "Constituency, Named Entities, Part-of-Speech"]
53 ];
54 KorAP.annotationHelper["corenlp/"] = [
55 ["Named Entity", "ne=" , "Combined"],
56 ["Named Entity", "ne_dewac_175m_600=" , "ne_dewac_175m_600"],
57 ["Named Entity", "ne_hgc_175m_600=", "ne_hgc_175m_600"]
58 ];
59 };
Nils Diewald5c5a7472015-04-02 22:13:38 +000060
Nils Diewald7c8ced22015-04-15 19:21:00 +000061 describe('KorAP.InputField', function () {
Akronfac16472018-07-26 16:47:21 +020062 beforeAll(beforeAllFunc);
63 afterAll(afterAllFunc);
Nils Diewald7c8ced22015-04-15 19:21:00 +000064 var input;
Nils Diewald1c546922015-04-13 01:56:19 +000065
Nils Diewald7c8ced22015-04-15 19:21:00 +000066 beforeEach(function () {
67 input = document.createElement("input");
68 input.setAttribute('type', "text");
69 input.setAttribute("value", "abcdefghijklmno");
70 input.style.position = 'absolute';
71 document.getElementsByTagName('body')[0].appendChild(input);
72 input.style.top = "20px";
73 input.style.left = "30px";
74 input.focus();
75 input.selectionStart = 5;
Nils Diewald5c5a7472015-04-02 22:13:38 +000076 });
77
Nils Diewald7c8ced22015-04-15 19:21:00 +000078 afterEach(function () {
79 document.getElementsByTagName("body")[0].removeChild(
Akron95abaf42018-04-26 15:33:22 +020080 input
Nils Diewald7c8ced22015-04-15 19:21:00 +000081 );
82 });
Nils Diewald5c5a7472015-04-02 22:13:38 +000083
Nils Diewald7c8ced22015-04-15 19:21:00 +000084 it('should be initializable', function () {
85 // Supports: context, searchField
86 var inputField = inputClass.create(input);
87 expect(inputField._element).not.toBe(undefined);
88 });
Nils Diewald19ccee92014-12-08 11:30:08 +000089
Nils Diewald7c8ced22015-04-15 19:21:00 +000090 it('should have text', function () {
91 expect(input.value).toEqual('abcdefghijklmno');
92 var inputField = inputClass.create(input);
Nils Diewald19ccee92014-12-08 11:30:08 +000093
Nils Diewald7c8ced22015-04-15 19:21:00 +000094 expect(inputField.value()).toEqual("abcdefghijklmno");
Nils Diewald19ccee92014-12-08 11:30:08 +000095
Nils Diewald7c8ced22015-04-15 19:21:00 +000096 expect(input.selectionStart).toEqual(5);
97 expect(inputField.element().selectionStart).toEqual(5);
Nils Diewald7148c6f2015-05-04 15:07:53 +000098 expect(inputField._split()[0]).toEqual("abcde");
99 expect(inputField._split()[1]).toEqual("fghijklmno");
Nils Diewald19ccee92014-12-08 11:30:08 +0000100
Nils Diewald7c8ced22015-04-15 19:21:00 +0000101 inputField.insert("xyz");
102 expect(inputField.value()).toEqual('abcdexyzfghijklmno');
Nils Diewald7148c6f2015-05-04 15:07:53 +0000103 expect(inputField._split()[0]).toEqual("abcdexyz");
104 expect(inputField._split()[1]).toEqual("fghijklmno");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000105 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000106
Nils Diewald7c8ced22015-04-15 19:21:00 +0000107 it('should be correctly positioned', function () {
108 expect(input.value).toEqual('abcdefghijklmno');
109 var inputField = inputClass.create(input);
110 document.getElementsByTagName("body")[0].appendChild(input);
111 inputField.reposition();
112 expect(input.style.left).toEqual("30px");
113 expect(inputField.mirror().style.left.match(/^(\d+)px$/)[1]).toBeGreaterThan(29);
114 expect(inputField.mirror().style.top.match(/^(\d+)px$/)[1]).toBeGreaterThan(20);
115 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000116
Nils Diewald7c8ced22015-04-15 19:21:00 +0000117 it('should have a correct context', function () {
118 expect(input.value).toEqual('abcdefghijklmno');
119 var inputField = inputClass.create(input);
120 expect(inputField.value()).toEqual("abcdefghijklmno");
121 expect(inputField.element().selectionStart).toEqual(5);
Nils Diewald7148c6f2015-05-04 15:07:53 +0000122 expect(inputField._split()[0]).toEqual("abcde");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000123 expect(inputField.context()).toEqual("abcde");
124 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000125
Nils Diewald7c8ced22015-04-15 19:21:00 +0000126 /*
127 it('should be correctly triggerable', function () {
128 // https://developer.mozilla.org/samples/domref/dispatchEvent.html
129 var hint = KorAP.Hint.create({ "inputField" : input });
130 emitKeyboardEvent(hint.inputField.element, "keypress", 20);
131 });
132 */
Nils Diewald19ccee92014-12-08 11:30:08 +0000133 });
134
Nils Diewald1c546922015-04-13 01:56:19 +0000135
Nils Diewald7c8ced22015-04-15 19:21:00 +0000136 describe('KorAP.ContextAnalyzer', function () {
Akronfac16472018-07-26 16:47:21 +0200137 beforeAll(beforeAllFunc);
138 afterAll(afterAllFunc);
139
Nils Diewald7c8ced22015-04-15 19:21:00 +0000140 it('should be initializable', function () {
141 var analyzer = contextClass.create(")");
142 expect(analyzer).toBe(undefined);
143 analyzer = contextClass.create(".+?");
144 expect(analyzer).not.toBe(undefined);
145 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000146
Nils Diewald7c8ced22015-04-15 19:21:00 +0000147 it('should check correctly', function () {
Akronfac16472018-07-26 16:47:21 +0200148
149 // Intialize KorAP.context
150 hintClass.create();
151
Nils Diewald7c8ced22015-04-15 19:21:00 +0000152 analyzer = contextClass.create(KorAP.context);
153 expect(analyzer.test("cnx/]cnx/c=")).toEqual("cnx/c=");
154 expect(analyzer.test("cnx/c=")).toEqual("cnx/c=");
155 expect(analyzer.test("cnx/c=np mate/m=mood:")).toEqual("mate/m=mood:");
156 expect(analyzer.test("impcnx/")).toEqual("impcnx/");
157 expect(analyzer.test("cnx/c=npcnx/")).toEqual("npcnx/");
158 expect(analyzer.test("mate/m=degree:pos corenlp/ne_dewac_175m_600="))
Akronfac16472018-07-26 16:47:21 +0200159 .toEqual("corenlp/ne_dewac_175m_600=");
Akron113cc1a2016-01-22 21:17:57 +0100160 expect(analyzer.test("corenlp/")).toEqual("corenlp/");
161 expect(analyzer.test("corenlp/c=")).toEqual("corenlp/c=");
162 expect(analyzer.test("corenlp/c=PP-")).toEqual("corenlp/c=PP-");
163 expect(analyzer.test("corenlp/c=XY-")).toEqual("corenlp/c=XY-");
Akroncff9bac2016-01-25 21:39:38 +0100164 expect(analyzer.test("sgbr/l=")).toEqual("sgbr/l=");
165 expect(analyzer.test("sgbr/lv=")).toEqual("sgbr/lv=");
166 expect(analyzer.test("sgbr/p=")).toEqual("sgbr/p=");
Akronee9ef4a2016-06-03 12:50:08 +0200167 expect(analyzer.test("")).toEqual(undefined);
168 expect(analyzer.test("abcdecnx/")).toEqual("abcdecnx/");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000169 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000170 });
171
Nils Diewald19ccee92014-12-08 11:30:08 +0000172
Nils Diewald7c8ced22015-04-15 19:21:00 +0000173 describe('KorAP.Hint', function () {
Akronfac16472018-07-26 16:47:21 +0200174 beforeAll(beforeAllFunc);
175 afterAll(afterAllFunc);
Nils Diewald19ccee92014-12-08 11:30:08 +0000176
Nils Diewald7c8ced22015-04-15 19:21:00 +0000177 beforeEach(function () {
178 input = document.createElement("input");
179 input.setAttribute("type", "text");
180 input.setAttribute("value", "abcdefghijklmno");
181 input.style.position = 'absolute';
182 input.style.top = "20px";
183 input.style.left = "30px";
184 input.focus();
185 input.selectionStart = 5;
186 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000187
Nils Diewald7c8ced22015-04-15 19:21:00 +0000188 it('should be initializable', function () {
Akronfac16472018-07-26 16:47:21 +0200189
Nils Diewald7c8ced22015-04-15 19:21:00 +0000190 // Supports: context, searchField
191 var hint = hintClass.create({
Akronfac16472018-07-26 16:47:21 +0200192 inputField : input
Nils Diewald7c8ced22015-04-15 19:21:00 +0000193 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000194
Nils Diewald7c8ced22015-04-15 19:21:00 +0000195 expect(hint).toBeTruthy();
196 });
Akron00cd4d12016-05-31 21:01:11 +0200197
Akron1a5a5872016-09-05 20:17:14 +0200198
Akron00cd4d12016-05-31 21:01:11 +0200199 it('should alert at char pos', function () {
200 var hint = hintClass.create({
Akron1a5a5872016-09-05 20:17:14 +0200201 inputField : input
Akron00cd4d12016-05-31 21:01:11 +0200202 });
203
204 expect(hint.active()).toBeFalsy();
205
206 expect(hint.alert(4, 'That does not work!')).toBeTruthy();
207
208 expect(hint.active()).toBeTruthy();
209
210 var container = hint.inputField().container();
211 expect(container.firstChild.classList.contains('hint')).toBe(true);
212 expect(container.firstChild.classList.contains('alert')).toBe(true);
213 expect(container.firstChild.textContent).toEqual('That does not work!');
214 expect(hint.inputField().mirrorValue()).toEqual('abcd');
215
216 expect(hint.alert(4, 'That does not work!')).toBeFalsy();
217
218 // Update - meaning: hide alert
219 hint.update();
220
221 expect(hint.alert().active).toBeFalsy();
Akron00cd4d12016-05-31 21:01:11 +0200222 expect(hint.active()).toBeFalsy();
Akron1a5a5872016-09-05 20:17:14 +0200223
224 // Show again
225 expect(hint.alert(5, 'That does not work!')).toBeTruthy();
226 expect(hint.inputField().mirrorValue()).toEqual('abcde');
227 expect(hint.alert().active).toBeTruthy();
228 expect(hint.active()).toBeTruthy();
229
230 // Show menu, hide alert!
231 hint.show(false);
232 expect(hint.active()).toBeTruthy();
233 expect(hint.inputField().mirrorValue()).toEqual('abcde');
234 expect(hint.alert().active).toBeFalsy();
235
Akronfac16472018-07-26 16:47:21 +0200236 // Show again
Akron1a5a5872016-09-05 20:17:14 +0200237 expect(hint.alert(5, 'That does not work!')).toBeTruthy();
238 expect(hint.inputField().mirrorValue()).toEqual('abcde');
239 expect(hint.alert().active).toBeTruthy();
240 expect(hint.active()).toBeTruthy();
241
242 // Show menu, hide alert!
243 hint.show(false);
244 expect(hint.active()).toBeTruthy();
245 expect(hint.inputField().mirrorValue()).toEqual('abcde');
246 expect(hint.alert().active).toBeFalsy();
Akronee9ef4a2016-06-03 12:50:08 +0200247 });
Akron00cd4d12016-05-31 21:01:11 +0200248
Akronee9ef4a2016-06-03 12:50:08 +0200249 it('should view main menu on default', function () {
250 var hint = hintClass.create({
Akron1a5a5872016-09-05 20:17:14 +0200251 inputField : input
Akronee9ef4a2016-06-03 12:50:08 +0200252 });
253
254 expect(hint.active()).toBeFalsy();
255
256 hint.inputField().insert('der Baum corenlp/');
Akronee9ef4a2016-06-03 12:50:08 +0200257
Akron8eaeb2e2016-08-29 18:26:28 +0200258 var cont = hint.inputField().container();
259
260 expect(cont.getElementsByTagName('div').length).toBe(1);
261 expect(cont.getElementsByTagName('ul').length).toBe(0);
262 expect(cont.firstChild).toEqual(cont.firstChild);
263
264 // Show menu, if a relevant context exists
265 // There is a menu for corenlp/
Akron02360e42016-06-07 13:41:12 +0200266 hint.show(false);
267
Akron8eaeb2e2016-08-29 18:26:28 +0200268 expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(1);
269 expect(hint.inputField().container().getElementsByTagName('li').length).toEqual(3);
Akron65c74352016-09-02 17:23:39 +0200270
Akron8eaeb2e2016-08-29 18:26:28 +0200271 // Hide the menu and focus on the input
272 hint.unshow();
Akron65c74352016-09-02 17:23:39 +0200273
274 expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(1);
275 expect(hint.inputField().container().getElementsByTagName('li').length).toEqual(0);
Akronee9ef4a2016-06-03 12:50:08 +0200276
Akron02360e42016-06-07 13:41:12 +0200277 hint.unshow();
Akron65c74352016-09-02 17:23:39 +0200278
Akronee9ef4a2016-06-03 12:50:08 +0200279 hint.inputField().insert(' hhhh');
Akron65c74352016-09-02 17:23:39 +0200280
Akronee9ef4a2016-06-03 12:50:08 +0200281 // show with context
Akron02360e42016-06-07 13:41:12 +0200282 hint.show(false);
Akron65c74352016-09-02 17:23:39 +0200283
Akronee9ef4a2016-06-03 12:50:08 +0200284 expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(4);
285 expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(1);
Akron02360e42016-06-07 13:41:12 +0200286 expect(hint.inputField().container().getElementsByTagName('li').length).toEqual(2);
287
Akronee9ef4a2016-06-03 12:50:08 +0200288 hint.unshow();
289 hint.inputField().insert(' aaaa/');
290
291 // show with context
292 hint.show(true);
293
Akron1a5a5872016-09-05 20:17:14 +0200294 expect(hint.inputField().container().getElementsByTagName('div').length).toEqual(1);
295 expect(hint.inputField().container().getElementsByTagName('ul').length).toEqual(0);
296 });
297
Akron95abaf42018-04-26 15:33:22 +0200298
299 it('should open menus depending on the context', function () {
300 var hint = hintClass.create({
301 inputField : input
302 });
303 hint.inputField().reset();
304
305 expect(hint.active()).toBeFalsy();
306
307 // show with context
308 hint.show(false);
309
310 expect(hint.active()).toBeTruthy();
311
312 expect(hint.inputField().container().getElementsByTagName('li')[0].firstChild.innerText).toEqual("Base Annotation");
313
314 // Type in prefix
315 hint.active().prefix("cor").show();
316 expect(hint.active().prefix()).toEqual("cor");
317
318 // Click first step
319 expect(hint.inputField().container().getElementsByTagName('li')[0].firstChild.firstChild.innerText).toEqual("Cor");
320 hint.inputField().container().getElementsByTagName('li')[0].click();
321
322 expect(hint.active()).toBeTruthy();
323
324 // Click second step
325 expect(hint.inputField().container().getElementsByTagName('li')[0].firstChild.innerText).toEqual("Named Entity");
326 hint.inputField().container().getElementsByTagName('li')[0].click()
327
328 // Invisible menu
329 expect(hint.inputField().container().getElementsByTagName('li')[0]).toBeUndefined();
330
331 // Inactive menu
332 expect(hint.active()).toBeFalsy();
333
334 // show with context
335 hint.show(false);
336
337 // No prefix
338 expect(hint.active().prefix()).toEqual("");
339 });
340
341
Akron1a5a5872016-09-05 20:17:14 +0200342 it('should not view main menu if context is mandatory', function () {
343 var hint = hintClass.create({
344 inputField : input
345 });
346
347 expect(hint.active()).toBeFalsy();
348
349 // Fine
350 hint.inputField().insert('der Baum corenlp/');
351 hint.show(true);
352 expect(hint.active()).toBeTruthy();
353
354 // Not analyzable
355 hint.inputField().insert('jhgjughjfhgnhfcvgnhj');
356 hint.show(true);
357 expect(hint.active()).toBeFalsy();
358
359 // Not available
360 hint.inputField().insert('jhgjughjfhgnhfcvgnhj/');
361 hint.show(true);
362 expect(hint.active()).toBeFalsy();
Akron00cd4d12016-05-31 21:01:11 +0200363 });
Akron5746ecf2018-06-23 10:57:24 +0200364
365
366 it('should show the assistant bar on blur', function () {
367 var hint = hintClass.create({
368 inputField : input
369 });
370 // Fine
371 hint.inputField().insert('der Baum corenlp/');
372 hint.show(true);
373 expect(hint.active()).toBeTruthy();
374
375 // Blur
376 hint.active().hideWithoutDestruction();
377 expect(hint.active()).toBeFalsy();
378 });
Akron65c74352016-09-02 17:23:39 +0200379
Akron02360e42016-06-07 13:41:12 +0200380 xit('should remove all menus on escape');
Nils Diewald19ccee92014-12-08 11:30:08 +0000381 });
382
Akron65c74352016-09-02 17:23:39 +0200383
Nils Diewald7c8ced22015-04-15 19:21:00 +0000384 describe('KorAP.HintMenuItem', function () {
Akronfac16472018-07-26 16:47:21 +0200385 beforeAll(beforeAllFunc);
386 afterAll(afterAllFunc);
387
Nils Diewald7c8ced22015-04-15 19:21:00 +0000388 it('should be initializable', function () {
389 expect(
Akronfac16472018-07-26 16:47:21 +0200390 function() { menuItemClass.create([]) }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000391 ).toThrow(new Error("Missing parameters"));
Nils Diewald19ccee92014-12-08 11:30:08 +0000392
Nils Diewald7c8ced22015-04-15 19:21:00 +0000393 expect(
Akronfac16472018-07-26 16:47:21 +0200394 function() { menuItemClass.create(['CoreNLP']) }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000395 ).toThrow(new Error("Missing parameters"));
Nils Diewald19ccee92014-12-08 11:30:08 +0000396
Nils Diewald7c8ced22015-04-15 19:21:00 +0000397 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
398 expect(menuItem.name()).toEqual('CoreNLP');
399 expect(menuItem.action()).toEqual('corenlp/');
400 expect(menuItem.desc()).toBeUndefined();
Nils Diewald19ccee92014-12-08 11:30:08 +0000401
Nils Diewald7c8ced22015-04-15 19:21:00 +0000402 menuItem = menuItemClass.create(
Akronfac16472018-07-26 16:47:21 +0200403 ['CoreNLP', 'corenlp/', 'It\'s funny']
Nils Diewald7c8ced22015-04-15 19:21:00 +0000404 );
405 expect(menuItem.name()).toEqual('CoreNLP');
406 expect(menuItem.action()).toEqual('corenlp/');
407 expect(menuItem.desc()).not.toBeUndefined();
408 expect(menuItem.desc()).toEqual('It\'s funny');
409 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000410
Akronfac16472018-07-26 16:47:21 +0200411
Nils Diewald7c8ced22015-04-15 19:21:00 +0000412 it('should have an element', function () {
413 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
414 expect(menuItem.element()).not.toBe(undefined);
415 expect(menuItem.element().nodeName).toEqual("LI");
Nils Diewald19ccee92014-12-08 11:30:08 +0000416
Nils Diewald7c8ced22015-04-15 19:21:00 +0000417 var title = menuItem.element().firstChild;
418 expect(title.nodeName).toEqual("SPAN");
419 expect(title.firstChild.nodeType).toEqual(3);
420 expect(title.firstChild.nodeValue).toEqual("CoreNLP");
421 expect(menuItem.element().childNodes[0]).not.toBe(undefined);
422 expect(menuItem.element().childNodes[1]).toBe(undefined);
Nils Diewald19ccee92014-12-08 11:30:08 +0000423
Nils Diewald7c8ced22015-04-15 19:21:00 +0000424 menuItem = menuItemClass.create(
Akronfac16472018-07-26 16:47:21 +0200425 ['CoreNLP', 'corenlp/', 'my DescRiption']
Nils Diewald7c8ced22015-04-15 19:21:00 +0000426 );
427 expect(menuItem.element()).not.toBe(undefined);
428 expect(menuItem.element().nodeName).toEqual("LI");
Nils Diewald19ccee92014-12-08 11:30:08 +0000429
Nils Diewald7c8ced22015-04-15 19:21:00 +0000430 title = menuItem.element().firstChild;
431 expect(title.nodeName).toEqual("SPAN");
432 expect(title.firstChild.nodeType).toEqual(3); // TextNode
433 expect(title.firstChild.nodeValue).toEqual("CoreNLP");
Nils Diewald19ccee92014-12-08 11:30:08 +0000434
Nils Diewald7c8ced22015-04-15 19:21:00 +0000435 expect(menuItem.element().childNodes[0]).not.toBe(undefined);
436 expect(menuItem.element().childNodes[1]).not.toBe(undefined);
Nils Diewald19ccee92014-12-08 11:30:08 +0000437
Nils Diewald7c8ced22015-04-15 19:21:00 +0000438 var desc = menuItem.element().lastChild;
439 expect(desc.nodeName).toEqual("SPAN");
440 expect(desc.firstChild.nodeType).toEqual(3); // TextNode
441 expect(desc.firstChild.nodeValue).toEqual("my DescRiption");
442 });
Nils Diewald1c546922015-04-13 01:56:19 +0000443
Nils Diewald19ccee92014-12-08 11:30:08 +0000444
Nils Diewald7c8ced22015-04-15 19:21:00 +0000445 it('should be activatable and deactivateable by class', function () {
446 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
447 expect(menuItem.active()).toBe(false);
448 expect(menuItem.element().getAttribute("class")).toBe(null);
449 menuItem.active(true);
450 expect(menuItem.active()).toBe(true);
451 expect(menuItem.element().getAttribute("class")).toEqual("active");
452 menuItem.active(false); // Is active
453 expect(menuItem.active()).toBe(false);
454 expect(menuItem.element().getAttribute("class")).toEqual("");
455 menuItem.active(true);
456 expect(menuItem.active()).toBe(true);
457 expect(menuItem.element().getAttribute("class")).toEqual("active");
Nils Diewald19ccee92014-12-08 11:30:08 +0000458
Nils Diewald7c8ced22015-04-15 19:21:00 +0000459 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
460 expect(menuItem.active()).toBe(false);
461 expect(menuItem.element().getAttribute("class")).toBe(null);
462 menuItem.active(false); // Is not active
463 expect(menuItem.active()).toBe(false);
464 expect(menuItem.element().getAttribute("class")).toBe(null);
465 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000466
Akronfac16472018-07-26 16:47:21 +0200467
Nils Diewald7c8ced22015-04-15 19:21:00 +0000468 it('should be set to boundary', function () {
469 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
470 expect(menuItem.active()).toBe(false);
471 expect(menuItem.element().getAttribute("class")).toBe(null);
Nils Diewald19ccee92014-12-08 11:30:08 +0000472
Nils Diewald7c8ced22015-04-15 19:21:00 +0000473 // Set active
474 menuItem.active(true);
475 expect(menuItem.active()).toBe(true);
476 expect(menuItem.noMore()).toBe(false);
477 expect(menuItem.element().getAttribute("class")).toEqual("active");
Nils Diewald19ccee92014-12-08 11:30:08 +0000478
Nils Diewald7c8ced22015-04-15 19:21:00 +0000479 // Set no more
480 menuItem.noMore(true);
481 expect(menuItem.active()).toBe(true);
482 expect(menuItem.noMore()).toBe(true);
483 expect(menuItem.element().getAttribute("class")).toEqual("active no-more");
Nils Diewald1c546922015-04-13 01:56:19 +0000484
Nils Diewald7c8ced22015-04-15 19:21:00 +0000485 // No no more
486 menuItem.noMore(false);
487 expect(menuItem.active()).toBe(true);
488 expect(menuItem.noMore()).toBe(false);
489 expect(menuItem.element().getAttribute("class")).toEqual("active");
Nils Diewald1c546922015-04-13 01:56:19 +0000490
Nils Diewald7c8ced22015-04-15 19:21:00 +0000491 // Set no more, deactivate
492 menuItem.noMore(true);
493 menuItem.active(false);
494 expect(menuItem.active()).toBe(false);
495 expect(menuItem.noMore()).toBe(true);
496 expect(menuItem.element().getAttribute("class")).toEqual("no-more");
Nils Diewald19ccee92014-12-08 11:30:08 +0000497
Nils Diewald7c8ced22015-04-15 19:21:00 +0000498 // Set active
499 menuItem.active(true);
500 expect(menuItem.active()).toBe(true);
501 expect(menuItem.noMore()).toBe(true);
502 expect(menuItem.element().getAttribute("class")).toEqual("no-more active");
503 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000504
Akronfac16472018-07-26 16:47:21 +0200505
Nils Diewald7c8ced22015-04-15 19:21:00 +0000506 it('should be highlightable', function () {
507 // Highlight in the middle
508 var menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
509 menuItem.highlight("ren");
510 expect(menuItem.element().innerHTML).toEqual("<span>Co<mark>reN</mark>LP</span>");
Nils Diewald19ccee92014-12-08 11:30:08 +0000511
Nils Diewald7c8ced22015-04-15 19:21:00 +0000512 menuItem.lowlight();
513 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
Nils Diewald19ccee92014-12-08 11:30:08 +0000514
Nils Diewald7c8ced22015-04-15 19:21:00 +0000515 // Starting highlight
516 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
517 menuItem.highlight("cor");
518 expect(menuItem.element().innerHTML).toEqual("<span><mark>Cor</mark>eNLP</span>");
Nils Diewald19ccee92014-12-08 11:30:08 +0000519
Nils Diewald7c8ced22015-04-15 19:21:00 +0000520 menuItem.lowlight();
521 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
522
523 // Starting highlight - short
524 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
525 menuItem.highlight("c");
526 expect(menuItem.element().innerHTML).toEqual("<span><mark>C</mark>oreNLP</span>");
527
528 menuItem.lowlight();
529 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
530
531 // Highlight at the end
532 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
533 menuItem.highlight("nlp");
534 expect(menuItem.element().innerHTML).toEqual("<span>Core<mark>NLP</mark></span>");
535
536 menuItem.lowlight();
537 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
538
539 // Highlight at the end - short
540 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
541 menuItem.highlight("p");
542 expect(menuItem.element().innerHTML).toEqual("<span>CoreNL<mark>P</mark></span>");
543
544 menuItem.lowlight();
545 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
546
547 // No highlight
548 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/']);
549 menuItem.highlight("xp");
550 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
551
552 menuItem.lowlight();
553 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span>");
554
555 // Highlight in the middle - first
556 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
557
558 menuItem.highlight("ren");
559 expect(menuItem.element().innerHTML).toEqual("<span>Co<mark>reN</mark>LP</span><span class=\"desc\">This is my Example</span>");
560
561 menuItem.lowlight();
562 expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Example</span>');
563
564 // Highlight in the middle - second
565 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
566 menuItem.highlight("ampl");
567 expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Ex<mark>ampl</mark>e</span>');
568
569 menuItem.lowlight();
570 expect(menuItem.element().innerHTML).toEqual('<span>CoreNLP</span><span class="desc">This is my Example</span>');
571
572 // Highlight in the middle - both
573 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
574
575 menuItem.highlight("e");
576 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>');
577
578 menuItem.lowlight();
579 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>");
580
581 // Highlight in the end - second
582 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
583 menuItem.highlight("le");
584 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Examp<mark>le</mark></span>");
585
586 menuItem.lowlight();
587 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>");
588
589 // Highlight at the beginning - second
590 menuItem = menuItemClass.create(['CoreNLP', 'corenlp/', 'This is my Example']);
591 menuItem.highlight("this");
592 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\"><mark>This</mark> is my Example</span>");
593
594 menuItem.lowlight();
595 expect(menuItem.element().innerHTML).toEqual("<span>CoreNLP</span><span class=\"desc\">This is my Example</span>");
596 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000597 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000598
Akronfac16472018-07-26 16:47:21 +0200599
Nils Diewald7c8ced22015-04-15 19:21:00 +0000600 describe('KorAP.HintMenu', function () {
Akronfac16472018-07-26 16:47:21 +0200601 beforeAll(beforeAllFunc);
602 afterAll(afterAllFunc);
603
Nils Diewald7c8ced22015-04-15 19:21:00 +0000604 var list = [
605 ["Constituency", "c=", "Example 1"],
606 ["Lemma", "l="],
607 ["Morphology", "m=", "Example 2"],
608 ["Part-of-Speech", "p="],
609 ["Syntax", "syn="]
610 ];
Nils Diewald19ccee92014-12-08 11:30:08 +0000611
Nils Diewald7c8ced22015-04-15 19:21:00 +0000612 it('should be initializable', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000613 var menu = menuClass.create(null, "cnx/", list);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000614 expect(menu.element().nodeName).toEqual('UL');
Akron65c74352016-09-02 17:23:39 +0200615 // expect(menu.element().style.opacity).toEqual("0");
Nils Diewald19ccee92014-12-08 11:30:08 +0000616
Nils Diewald7c8ced22015-04-15 19:21:00 +0000617 menu.limit(8);
Nils Diewald19ccee92014-12-08 11:30:08 +0000618
Nils Diewald7c8ced22015-04-15 19:21:00 +0000619 // view
620 menu.show();
Akron6ed13992016-05-23 18:06:05 +0200621 expect(menu.prefix()).toBe('');
Nils Diewald19ccee92014-12-08 11:30:08 +0000622
Nils Diewald7c8ced22015-04-15 19:21:00 +0000623 // First element in list
624 expect(menu.item(0).active()).toBe(true);
625 expect(menu.item(0).noMore()).toBe(true);
626
627 // Middle element in list
628 expect(menu.item(2).active()).toBe(false);
629 expect(menu.item(2).noMore()).toBe(false);
Nils Diewald19ccee92014-12-08 11:30:08 +0000630
Nils Diewald7c8ced22015-04-15 19:21:00 +0000631 // Last element in list
632 expect(menu.item(menu.length() - 1).active()).toBe(false);
633 expect(menu.item(menu.length() - 1).noMore()).toBe(true);
Akron6ed13992016-05-23 18:06:05 +0200634
635 expect(menu.shownItem(0).active()).toBeTruthy();
636 expect(menu.shownItem(0).lcField()).toEqual(' constituency example 1');
637 expect(menu.shownItem(1).lcField()).toEqual(' lemma');
638 expect(menu.shownItem(2).lcField()).toEqual(' morphology example 2');
639
640 menu.next();
641 expect(menu.shownItem(1).active()).toBeTruthy();
642
643 menu.next();
644 expect(menu.shownItem(2).active()).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000645 });
Nils Diewald19ccee92014-12-08 11:30:08 +0000646 });
647});