blob: 5fc7b0390b411cbaeb7983bf72c9b080400c1b2c [file] [log] [blame]
Leo Repp56904d22021-04-26 15:53:22 +02001define(
2 ['alwaysmenu', 'menu/item', 'menu/prefix', 'menu/lengthField', 'alwaysentry'],
3 function (alwaysMenuClass, menuItemClass, prefixClass, lengthFieldClass, alwaysEntryClass) {
4
5 //These class definitions were taken from menuSpec for a guideline on how to procede
6
7 // The OwnAlwaysMenu item
8 const OwnAlwaysMenuItem = {
9 create : function (params) {
10 return Object.create(menuItemClass).upgradeTo(OwnAlwaysMenuItem)._init(params);
11 },
12 content : function (content) {
13 if (arguments.length === 1) {
14 this._content = content;
15 };
16 return this._content;
17 },
18 _init : function (params) {
19 if (params[0] === undefined)
20 throw new Error("Missing parameters");
21
22 this._content = document.createTextNode(params[0]);
23 this._lcField = ' ' + this.content().textContent.toLowerCase();
24
25 return this;
26 }
27 };
28
29 // The OwnAlwaysMenu
30 let OwnAlwaysMenu = {
31 create : function (list) {
32 return alwaysMenuClass.create(list, { itemClass : OwnAlwaysMenuItem } )
33 .upgradeTo(OwnAlwaysMenu);
34 }
35 };
36
37
38
39 // HintMenuItem
40 const HintMenuItem = {
41 create : function (params) {
42 return Object.create(menuItemClass)
43 .upgradeTo(HintMenuItem)
44 ._init(params);
45 },
46 content : function (content) {
47 if (arguments.length === 1) {
48 this._content = content;
49 };
50 return this._content;
51 },
52 _init : function (params) {
53 if (params[0] === undefined || params[1] === undefined)
54 throw new Error("Missing parameters");
55
56 this._name = params[0];
57 this._action = params[1];
58 this._lcField = ' ' + this._name.toLowerCase();
59
60 if (params.length > 2) {
61 this._desc = params[2];
62 this._lcField += " " + this._desc.toLowerCase();
63 };
64
65 return this;
66 },
67
68 name : function () {
69 return this._name;
70 },
71 action : function () {
72 return this._action;
73 },
74 desc : function () {
75 return this._desc;
76 },
77 element : function () {
78 // already defined
79 if (this._el !== undefined)
80 return this._el;
81
82 // Create list item
83 var li = document.createElement("li");
84 li.setAttribute("data-action", this._action);
85
86 // Create title
87 var name = document.createElement("strong");
88 name.appendChild(document.createTextNode(this._name));
89
90 li.appendChild(name);
91
92 // Create description
93 if (this._desc !== undefined) {
94 var desc = document.createElement("span");
95 desc.appendChild(document.createTextNode(this._desc));
96 li.appendChild(desc);
97 };
98 return this._el = li;
99 }
100 };
101
102
103 // HintMenu
104 const HintMenu = {
105 create : function (context, list) {
106 var obj = alwaysMenuClass.create(list, {itemClass : HintMenuItem} )
107 .upgradeTo(HintMenu);
108 obj._context = context;
109 return obj;
110 }
111 };
112
113
114 // The ComplexMenuItem
115 const ComplexMenuItem = {
116 create : function (params) {
117 return Object.create(menuItemClass)
118 .upgradeTo(ComplexMenuItem)
119 ._init(params);
120 },
121 content : function (content) {
122 if (arguments.length === 1) {
123 this._content = content;
124 };
125 return this._content;
126 },
127 _init : function (params) {
128 if (params[0] === undefined)
129 throw new Error("Missing parameters");
130
131 var r = document.createElement('div');
132 for (var i = 1; i <= params.length; i++) {
133 var h = document.createElement('h' + i);
134 h.appendChild(document.createTextNode(params[i-1]));
135 r.appendChild(h);
136 };
137
138 this._content = r;
139 this._lcField = ' ' + this.content().textContent.toLowerCase();
140
141 return this;
142 }
143 };
144
145
146 describe('KorAP.AlwaysMenu', function () {
147 var list = [
148 ["Constituency", "c=", "Example 1"],
149 ["Lemma", "l="],
150 ["Morphology", "m=", "Example 2"],
151 ["Part-of-Speech", "p="],
152 ["Syntax", "syn="]
153 ];
154
155 var listMultiPrefix = [
156 ["PP","PP ","Personal Pronoun"],
157 ["PPP","PPP ","Personal Pronoun, Plural"],
158 ["PPPA","PPPA ","Personal Pronoun, Plural, Acc."],
159 ["PPPD","PPPD ","Personal Pronoun, Plural, Dative"],
160 ["PPPR","PPPR ","Personal Pronoun, Plural, Direct"],
161 ["PPPO","PPPO ","Personal Pronoun, Plural, Oblique"],
162 ["PPS","PPS ","Personal Pronoun, Singular"],
163 ["PPSA","PPSA ","Personal Pronoun, Singular, Accusative"],
164 ["PPSD","PPSD ","Personal Pronoun, Singular, Dative"],
165 ["PPSR","PPSR ","Personal Pronoun, Singular, Direct"],
166 ["PPSN","PPSN ","Personal Pronoun, Singular, Nominative"],
167 ["PPSO","PPSO ","Personal Pronoun, Singular, Oblique"]
168 ];
169
170 var demolist = [
171 ['Titel', 'title'],
172 ['Untertitel', 'subTitle'],
173 ['Veröffentlichungsdatum', 'pubDate'],
174 ['Länge', 'length'],
175 ['Autor', 'author']
176 ];
177
178 var demolonglist = [
179 ['Titel', 'title'],
180 ['Untertitel', 'subTitle'],
181 ['Veröffentlichungsdatum', 'pubDate'],
182 ['Länge', 'length'],
183 ['Autor', 'author'],
184 ['Genre', 'genre'],
185 ['corpusID', 'corpusID'],
186 ['docID', 'docID'],
187 ['textID', 'textID'],
188 ];
189
190 it('should be initializable', function () {
191 var list = [
192 ["Constituency"],
193 ["Lemma"],
194 ["Morphology"],
195 ["Part-of-Speech"],
196 ["Syntax"]
197 ];
198
199 var menu = OwnAlwaysMenu.create(list);
200 menu._firstActive = true;
201 expect(menu.itemClass()).toEqual(OwnAlwaysMenuItem);
202 expect(menu._notItemElements).toEqual(4);
marcrusian235a23a2021-05-26 14:28:11 +0200203 expect(menu.element().getElementsByClassName("entry").length).toEqual(1);
204 expect(menu.element().getElementsByClassName("entry").length).toEqual(1);
205 expect(menu.element().getElementsByClassName("entry")[0].innerHTML).toEqual("Speichern");
Leo Repp56904d22021-04-26 15:53:22 +0200206 expect(menu.alwaysEntry().element().innerHTML).toEqual("Speichern");
207 //expect(menu.element().childNodes[3].innerHTML).toEqual("Speichern"); //?
208 // getElementsByClassName funktioniert bei allen Kindern.
209
210
211 // view
212 menu.show();
213
214 expect(menu.alwaysEntry().active()).toBe(false);
215 });
216
217 it('should be visible', function () {
218 var menu = HintMenu.create("cnx/", list);
219 expect(menu.removeItems()).toBe(undefined);
220 menu.limit(3);
221
222 expect(menu.show()).toBe(true);
223
Leo Repp7b0fbf92021-07-14 11:25:59 +0200224 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
225 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>");
226 expect(menu.directElementChildrenByTagName("li")[1].getAttribute("data-action")).toEqual("l=");
227 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
228 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Leo Repp56904d22021-04-26 15:53:22 +0200229
230 // Check boundaries
Leo Repp7b0fbf92021-07-14 11:25:59 +0200231 expect(menu.directElementChildrenByTagName("li")[0].classList.contains("no-more")).toBe(true);
232 expect(menu.directElementChildrenByTagName("li")[1].classList.contains("no-more")).toBe(false);
233 expect(menu.directElementChildrenByTagName("li")[2].classList.contains("no-more")).toBe(false);
Leo Repp56904d22021-04-26 15:53:22 +0200234 });
235
236 it('should be filterable', function () {
237 var menu = HintMenu.create("cnx/", list);
238 menu.limit(3);
239 expect(menu.prefix("o").show()).toBe(true);
240 expect(menu.alwaysEntryValue("o").alwaysEntryValue()).toEqual("o");
241 expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("o");
242 expect(menu.alwaysEntry().element().innerHTML).toEqual("Speichern");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200243 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
244 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
245 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
246 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Leo Repp56904d22021-04-26 15:53:22 +0200247
248 // Check boundaries
Leo Repp7b0fbf92021-07-14 11:25:59 +0200249 expect(menu.directElementChildrenByTagName("li")[0].classList.contains("no-more")).toBe(true);
250 expect(menu.directElementChildrenByTagName("li")[1].classList.contains("no-more")).toBe(false);
251 expect(menu.directElementChildrenByTagName("li")[2].classList.contains("no-more")).toBe(true);
Leo Repp56904d22021-04-26 15:53:22 +0200252
253 menu.limit(2);
254
255 expect(menu.prefix("o").show()).toBe(true);
256 expect(menu.alwaysEntryValue("o").alwaysEntryValue()).toEqual("o");
257 expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("o");
258 expect(menu.alwaysEntry().element().innerHTML).toEqual("Speichern");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200259 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
260 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
261 expect(menu.directElementChildrenByTagName("li")[2]).toBe(undefined);
Leo Repp56904d22021-04-26 15:53:22 +0200262
263 // Check boundaries
Leo Repp7b0fbf92021-07-14 11:25:59 +0200264 expect(menu.directElementChildrenByTagName("li")[0].classList.contains("no-more")).toBe(true);
265 expect(menu.directElementChildrenByTagName("li")[1].classList.contains("no-more")).toBe(false);
266 expect(menu.directElementChildrenByTagName("li")[2]).toBe(undefined);
Leo Repp56904d22021-04-26 15:53:22 +0200267
268 expect(menu.prefix("e").show()).toBe(true);
269 expect(menu.alwaysEntryValue("e").alwaysEntryValue()).toEqual("e");
270 expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("e");
271 expect(menu.alwaysEntry().element().innerHTML).toEqual("Speichern");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200272 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
273 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
274 expect(menu.directElementChildrenByTagName("li")[2]).toBe(undefined);
Leo Repp56904d22021-04-26 15:53:22 +0200275
276 menu.limit(5);
277 expect(menu.prefix("a").show()).toBe(true);
278 expect(menu.alwaysEntryValue("a").alwaysEntryValue()).toEqual("a");
279 expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("a");
280 expect(menu.alwaysEntry().element().innerHTML).toEqual("Speichern");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200281 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Ex<mark>a</mark>mple 1</span>");
282 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Lemm<mark>a</mark></strong>");
283 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Ex<mark>a</mark>mple 2</span>");
284 expect(menu.directElementChildrenByTagName("li")[3].innerHTML).toEqual("<strong>P<mark>a</mark>rt-of-Speech</strong>");
285 expect(menu.directElementChildrenByTagName("li")[4].innerHTML).toEqual("<strong>Synt<mark>a</mark>x</strong>");
286 expect(menu.directElementChildrenByTagName("li")[5]).toBe(undefined);
Leo Repp56904d22021-04-26 15:53:22 +0200287 });
288
289
290 it('should be nextable', function () {
291 var menu = HintMenu.create("cnx/", list);
292 menu._firstActive = true;
293
294 expect(menu._prefix.active()).toBe(false);
295
296 // Show only 3 items
297 menu.limit(3);
298 expect(menu.show()).toBe(true);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200299 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200300 expect(menu.shownItem(0).active()).toBe(true);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200301 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200302 expect(menu.shownItem(1).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200303 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200304 expect(menu.shownItem(2).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200305 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Leo Repp56904d22021-04-26 15:53:22 +0200306 expect(menu.alwaysEntry().active()).toBe(false);
307
308 // Activate next (1)
309 menu.next();
Leo Repp7b0fbf92021-07-14 11:25:59 +0200310 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200311 expect(menu.shownItem(0).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200312 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200313 expect(menu.shownItem(1).active()).toBe(true);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200314 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200315 expect(menu.shownItem(2).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200316 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Leo Repp56904d22021-04-26 15:53:22 +0200317 expect(menu.alwaysEntry().active()).toBe(false);
318
319 // Activate next (2)
320 menu.next();
Leo Repp7b0fbf92021-07-14 11:25:59 +0200321 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200322 expect(menu.shownItem(0).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200323 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200324 expect(menu.shownItem(1).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200325 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200326 expect(menu.shownItem(2).active()).toBe(true);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200327 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Leo Repp56904d22021-04-26 15:53:22 +0200328 expect(menu.alwaysEntry().active()).toBe(false);
329
330 // Activate next (3)
331 // scroll!
332 menu.next();
Leo Repp7b0fbf92021-07-14 11:25:59 +0200333 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Lemma</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200334 expect(menu.shownItem(0).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200335 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200336 expect(menu.shownItem(1).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200337 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200338 expect(menu.shownItem(2).active()).toBe(true);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200339 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Leo Repp56904d22021-04-26 15:53:22 +0200340 expect(menu.alwaysEntry().active()).toBe(false);
341
342 // Activate next (4)
343 menu.next();
Leo Repp7b0fbf92021-07-14 11:25:59 +0200344 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200345 expect(menu.shownItem(0).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200346 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200347 expect(menu.shownItem(1).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200348 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Syntax</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200349 expect(menu.shownItem(2).active()).toBe(true);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200350 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Leo Repp56904d22021-04-26 15:53:22 +0200351 expect(menu.alwaysEntry().active()).toBe(false);
352
353 // Activate next (5) - Entry / Speichern
354 menu.next();
Leo Repp7b0fbf92021-07-14 11:25:59 +0200355 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200356 expect(menu.shownItem(0).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200357 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200358 expect(menu.shownItem(1).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200359 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Syntax</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200360 expect(menu.shownItem(2).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200361 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Leo Repp56904d22021-04-26 15:53:22 +0200362 expect(menu.alwaysEntry().active()).toBe(true);
363
364 // Activate next (6) - ROLL
365 menu.next();
Leo Repp7b0fbf92021-07-14 11:25:59 +0200366 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200367 expect(menu.shownItem(0).active()).toBe(true);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200368 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200369 expect(menu.shownItem(1).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200370 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200371 expect(menu.shownItem(2).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200372 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Leo Repp56904d22021-04-26 15:53:22 +0200373 expect(menu.alwaysEntry().active()).toBe(false);
374
375 // Active next (7)
376 menu.next();
Leo Repp7b0fbf92021-07-14 11:25:59 +0200377 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200378 expect(menu.shownItem(0).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200379 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200380 expect(menu.shownItem(1).active()).toBe(true);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200381 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200382 expect(menu.shownItem(2).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200383 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Leo Repp56904d22021-04-26 15:53:22 +0200384 expect(menu.alwaysEntry().active()).toBe(false);
385
386 expect(menu._prefix.active()).toBe(false);
387 });
388
389 it('should be nextable without active field', function () {
390 var menu = HintMenu.create("cnx/", list);
391 menu.limit(3);
392 expect(menu.show()).toBe(true);
393 menu.next();
394 expect(menu.shownItem(0).active()).toEqual(true);
395 });
396
397
398 it('should be prevable', function () {
399 var menu = HintMenu.create("cnx/", list);
400 menu._firstActive = true;
401 menu.limit(3);
402 expect(menu.show()).toBe(true);
403 expect(menu._prefix.active()).toBe(false);
404 expect(menu.alwaysEntryValue()).toBe("");
405
Leo Repp7b0fbf92021-07-14 11:25:59 +0200406 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200407 expect(menu.shownItem(0).active()).toBe(true);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200408 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200409 expect(menu.shownItem(1).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200410 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200411 expect(menu.shownItem(2).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200412 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Leo Repp56904d22021-04-26 15:53:22 +0200413 expect(menu.alwaysEntry().active()).toBe(false);
414
415
416 // Activate prev (1) - roll to bottom
417 menu.prev();
Leo Repp7b0fbf92021-07-14 11:25:59 +0200418 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200419 expect(menu.shownItem(0).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200420 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200421 expect(menu.shownItem(1).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200422 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200423 expect(menu.shownItem(2).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200424 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Leo Repp56904d22021-04-26 15:53:22 +0200425 expect(menu.alwaysEntry().active()).toBe(true);
426
427 // Activate prev (2)
428 menu.prev();
Leo Repp7b0fbf92021-07-14 11:25:59 +0200429 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200430 expect(menu.shownItem(0).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200431 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200432 expect(menu.shownItem(1).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200433 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Syntax</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200434 expect(menu.shownItem(2).active()).toBe(true);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200435 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Leo Repp56904d22021-04-26 15:53:22 +0200436 expect(menu.alwaysEntry().active()).toBe(false);
437
438 // Activate prev (3)
439 menu.prev();
Leo Repp7b0fbf92021-07-14 11:25:59 +0200440 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200441 expect(menu.shownItem(0).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200442 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200443 expect(menu.shownItem(1).active()).toBe(true);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200444 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Syntax</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200445 expect(menu.shownItem(2).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200446 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Leo Repp56904d22021-04-26 15:53:22 +0200447 expect(menu.alwaysEntry().active()).toBe(false);
448
449 // Activate prev (4)
450 menu.prev();
451 expect(menu.shownItem(0).name()).toEqual("Morphology");
452 expect(menu.shownItem(0).active()).toBe(true);
453 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
454 expect(menu.shownItem(1).active()).toBe(false);
455 expect(menu.shownItem(2).name()).toEqual("Syntax");
456 expect(menu.shownItem(2).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200457 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Leo Repp56904d22021-04-26 15:53:22 +0200458 expect(menu.alwaysEntry().active()).toBe(false);
459
460 // Activate prev (5)
461 menu.prev();
462 expect(menu.shownItem(0).name()).toEqual("Lemma");
463 expect(menu.shownItem(0).active()).toBe(true);
464 expect(menu.shownItem(1).name()).toEqual("Morphology");
465 expect(menu.shownItem(1).active()).toBe(false);
466 expect(menu.shownItem(2).name()).toEqual("Part-of-Speech");
467 expect(menu.shownItem(2).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200468 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Leo Repp56904d22021-04-26 15:53:22 +0200469 expect(menu.alwaysEntry().active()).toBe(false);
470
471 // Activate prev (6)
472 menu.prev();
473 expect(menu.shownItem(0).name()).toEqual("Constituency");
474 expect(menu.shownItem(0).active()).toBe(true);
475 expect(menu.shownItem(1).name()).toEqual("Lemma");
476 expect(menu.shownItem(1).active()).toBe(false);
477 expect(menu.shownItem(2).name()).toEqual("Morphology");
478 expect(menu.shownItem(2).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200479 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Leo Repp56904d22021-04-26 15:53:22 +0200480 expect(menu.alwaysEntry().active()).toBe(false);
481
482 // Activate next (7)
483 menu.next();
484 expect(menu.shownItem(0).name()).toEqual("Constituency");
485 expect(menu.shownItem(0).active()).toBe(false);
486 expect(menu.shownItem(1).name()).toEqual("Lemma");
487 expect(menu.shownItem(1).active()).toBe(true);
488 expect(menu.shownItem(2).name()).toEqual("Morphology");
489 expect(menu.shownItem(2).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200490 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Leo Repp56904d22021-04-26 15:53:22 +0200491 expect(menu.alwaysEntry().active()).toBe(false);
492
493 // Activate prev (8)
494 menu.prev();
495
496 // Activate prev (9) - Roll again
497 menu.prev();
498 expect(menu.shownItem(0).name()).toEqual("Constituency");
499 expect(menu.shownItem(0).active()).toBe(false);
500 expect(menu.shownItem(1).name()).toEqual("Lemma");
501 expect(menu.shownItem(1).active()).toBe(false);
502 expect(menu.shownItem(2).name()).toEqual("Morphology");
503 expect(menu.shownItem(2).active()).toBe(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200504 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Leo Repp56904d22021-04-26 15:53:22 +0200505 expect(menu.alwaysEntry().active()).toBe(true);
506
507 // Activate prev (10)
508 menu.prev()
509 expect(menu.shownItem(0).name()).toEqual("Morphology");
510 expect(menu.shownItem(0).active()).toBe(false);
511 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
512 expect(menu.shownItem(1).active()).toBe(false);
513 expect(menu.shownItem(2).name()).toEqual("Syntax");
514 expect(menu.shownItem(2).active()).toBe(true);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200515 expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined);
Leo Repp56904d22021-04-26 15:53:22 +0200516 expect(menu.alwaysEntry().active()).toBe(false);
517 expect(menu._prefix.active()).toBe(false);
518 expect(menu.alwaysEntryValue()).toBe("");
519 expect(menu.alwaysEntry().element().innerHTML).toBe("Speichern");
520
521 });
522
523 it('should be prevable without active field', function () {
524 var menu = HintMenu.create("cnx/", list);
525 menu.limit(3);
526 expect(menu.show()).toBe(true);
527 menu.prev();
528 expect(menu.alwaysEntry().active()).toBe(true);
529 expect(menu.shownItem(2).active()).toEqual(false);
530 expect(menu.shownItem(2).lcField()).toEqual(' morphology example 2');
531 menu.prev()
532 expect(menu.shownItem(2).active()).toEqual(true);
533 expect(menu.shownItem(2).lcField()).toEqual(' syntax');
534 });
535
536 it('should be navigatable and filterable (prefix = "o")', function () {
537 var menu = HintMenu.create("cnx/", list);
538 menu._firstActive = true;
539 menu.limit(2);
540
541 expect(menu.prefix("o").show()).toBe(true);
542 expect(menu.alwaysEntryValue("o").alwaysEntryValue()).toBe("o");
543 expect(menu._prefix.active()).toBe(false);
544 expect(menu.alwaysEntry().active()).toBe(false);
545
546 expect(menu.shownItem(0).name()).toEqual("Constituency");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200547 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200548 expect(menu.shownItem(0).active()).toBe(true);
549 expect(menu.shownItem(1).name()).toEqual("Morphology");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200550 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200551 expect(menu.shownItem(1).active()).toBe(false);
552 expect(menu.shownItem(2)).toBe(undefined);
553
554 // Next (1)
555 menu.next();
556 expect(menu.shownItem(0).name()).toEqual("Constituency");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200557 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200558 expect(menu.shownItem(0).active()).toBe(false);
559 expect(menu.shownItem(1).name()).toEqual("Morphology");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200560 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200561 expect(menu.shownItem(1).active()).toBe(true);
562 expect(menu.shownItem(2)).toBe(undefined);
563
564 // Next (2)
565 menu.next();
566 expect(menu.shownItem(0).name()).toEqual("Morphology");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200567 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200568 expect(menu.shownItem(0).active()).toBe(false);
569 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200570 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200571 expect(menu.shownItem(1).active()).toBe(true);
572 expect(menu.shownItem(2)).toBe(undefined);
573
574 // Next (3) - to prefix
575 menu.next();
576 expect(menu.shownItem(0).name()).toEqual("Morphology");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200577 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200578 expect(menu.shownItem(0).active()).toBe(false);
579 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200580 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200581 expect(menu.shownItem(1).active()).toBe(false);
582 expect(menu.shownItem(2)).toBe(undefined);
583 expect(menu._prefix.active()).toBe(true);
584 expect(menu.alwaysEntry().active()).toBe(false);
585
586 // Next (4) - to entry
587 menu.next();
588 expect(menu.shownItem(0).name()).toEqual("Morphology");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200589 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200590 expect(menu.shownItem(0).active()).toBe(false);
591 expect(menu.shownItem(1).name()).toEqual("Part-of-Speech");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200592 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200593 expect(menu.shownItem(1).active()).toBe(false);
594 expect(menu.shownItem(2)).toBe(undefined);
595 expect(menu._prefix.active()).toBe(false);
596 expect(menu.alwaysEntry().active()).toBe(true);
597
598 menu.next();
599 expect(menu.shownItem(0).name()).toEqual("Constituency");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200600 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200601 expect(menu.shownItem(0).active()).toBe(true);
602 expect(menu.shownItem(1).name()).toEqual("Morphology");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200603 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200604 expect(menu.shownItem(1).active()).toBe(false);
605 expect(menu.shownItem(2)).toBe(undefined);
606
607 expect(menu.prefix("o").show()).toBe(true);
608 expect(menu.alwaysEntryValue("o").alwaysEntryValue()).toBe("o");
609 expect(menu._prefix.active()).toBe(false);
610 expect(menu.alwaysEntry().active()).toBe(false);
611 });
612
613
614 it('should be navigatable and filterable (prefix = "ex", "e")', function () {
615 var menu = HintMenu.create("cnx/", list);
616 menu._firstActive = true;
617
618 menu.limit(2);
619 expect(menu.prefix("ex").show()).toBe(true);
620 expect(menu.alwaysEntryValue("ex").alwaysEntryValue()).toBe("ex");
621 expect(menu._prefix.active()).toBe(false);
622 expect(menu.alwaysEntry().active()).toBe(false);
623
624 expect(menu.shownItem(0).name()).toEqual("Constituency");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200625 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200626 expect(menu.shownItem(0).active()).toBe(true);
627 expect(menu.shownItem(1).name()).toEqual("Morphology");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200628 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200629 expect(menu.shownItem(1).active()).toBe(false);
630 expect(menu.shownItem(2)).toBe(undefined);
631
632 // Next (1)
633 menu.next();
634 expect(menu.shownItem(0).name()).toEqual("Constituency");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200635 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200636 expect(menu.shownItem(0).active()).toBe(false);
637 expect(menu.shownItem(1).name()).toEqual("Morphology");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200638 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200639 expect(menu.shownItem(1).active()).toBe(true);
640 expect(menu.shownItem(2)).toBe(undefined);
641 expect(menu.alwaysEntryValue()).toBe("ex");
642 expect(menu._prefix.active()).toBe(false);
643 expect(menu.alwaysEntry().active()).toBe(false);
644
645 // Next (2)
646 menu.next();
647
648 expect(menu.prefix()).toEqual('ex');
649 expect(menu.shownItem(0).name()).toEqual("Constituency");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200650 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200651 expect(menu.shownItem(0).active()).toBe(false);
652
653 expect(menu.shownItem(1).name()).toEqual("Morphology");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200654 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200655 expect(menu.shownItem(1).active()).toBe(false);
656 expect(menu.shownItem(2)).toBe(undefined);
657 expect(menu.alwaysEntryValue()).toBe("ex");
658 expect(menu._prefix.active()).toBe(true);
659 expect(menu.alwaysEntry().active()).toBe(false);
660
661 // Reset limit
662 menu.limit(5);
663
664 // Change show
665 expect(menu.prefix("e").show()).toBe(true);
666 expect(menu.alwaysEntryValue("e").alwaysEntryValue()).toBe("e");
667 expect(menu._prefix.active()).toBe(false);
668 expect(menu.alwaysEntry().active()).toBe(false);
669 expect(menu.shownItem(0).name()).toEqual("Constituency");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200670 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200671 expect(menu.shownItem(0).active()).toBe(true);
672 expect(menu.shownItem(1).name()).toEqual("Morphology");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200673 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200674 expect(menu.shownItem(1).active()).toBe(false);
675 expect(menu.shownItem(2)).toBe(undefined);
676
677 // Next (1)
678 menu.next();
679 expect(menu._prefix.active()).toBe(false);
680 expect(menu.prefix()).toEqual('e');
681 expect(menu.shownItem(0).name()).toEqual("Constituency");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200682 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200683 expect(menu.shownItem(0).active()).toBe(false);
684 expect(menu.shownItem(1).name()).toEqual("Morphology");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200685 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200686 expect(menu.shownItem(1).active()).toBe(true);
687 expect(menu.shownItem(2)).toBe(undefined);
688 expect(menu._prefix.active()).toBe(false);
689 expect(menu.alwaysEntry().active()).toBe(false);
690
691 // Next (2)
692 menu.next();
693 expect(menu._prefix.active()).toBe(true);
694 expect(menu.shownItem(0).name()).toEqual("Constituency");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200695 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200696 expect(menu.shownItem(0).active()).toBe(false);
697 expect(menu.shownItem(1).name()).toEqual("Morphology");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200698 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200699 expect(menu.shownItem(1).active()).toBe(false);
700 expect(menu.shownItem(2)).toBe(undefined);
701 expect(menu._prefix.active()).toBe(true);
702 expect(menu.alwaysEntry().active()).toBe(false);
703
704 // Next (2.5)
705 menu.next();
706 expect(menu._prefix.active()).toBe(false);
707 expect(menu.shownItem(0).name()).toEqual("Constituency");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200708 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200709 expect(menu.shownItem(0).active()).toBe(false);
710 expect(menu.shownItem(1).name()).toEqual("Morphology");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200711 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200712 expect(menu.shownItem(1).active()).toBe(false);
713 expect(menu.shownItem(2)).toBe(undefined);
714 expect(menu._prefix.active()).toBe(false);
715 expect(menu.alwaysEntry().active()).toBe(true);
716
717 // Next (3)
718 menu.next();
719 expect(menu._prefix.active()).toBe(false);
720 expect(menu.shownItem(0).name()).toEqual("Constituency");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200721 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200722 expect(menu.shownItem(0).active()).toBe(true);
723 expect(menu.shownItem(1).name()).toEqual("Morphology");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200724 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200725 expect(menu.shownItem(1).active()).toBe(false);
726 expect(menu.shownItem(2)).toBe(undefined);
727
728 expect(menu.alwaysEntryValue()).toBe("e");
729 expect(menu._prefix.active()).toBe(false);
730 expect(menu.alwaysEntry().active()).toBe(false);
731 });
732
733 it('should be filterable (multiple prefix = "pro sin")', function () {
734 var menu = HintMenu.create("drukola/p=", listMultiPrefix);
735 menu._firstActive = true;
736
737 menu.limit(2);
738 expect(menu.prefix("pro sin").show()).toBe(true);
739 expect(menu.alwaysEntryValue("pro sin").alwaysEntryValue()).toBe("pro sin");
740 expect(menu._prefix.active()).toBe(false);
741 expect(menu.alwaysEntry().active()).toBe(false);
742 expect(menu.shownItem(0).name()).toEqual("PPS");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200743 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual(
Leo Repp56904d22021-04-26 15:53:22 +0200744 "<strong>PPS</strong><span>Personal <mark>Pro</mark>noun, <mark>Sin</mark>gular</span>"
745 );
746
747 expect(menu.shownItem(0).active()).toBe(true);
748 expect(menu.shownItem(1).name()).toEqual("PPSA");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200749 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>PPSA</strong><span>Personal <mark>Pro</mark>noun, <mark>Sin</mark>gular, Accusative</span>");
Leo Repp56904d22021-04-26 15:53:22 +0200750 expect(menu.shownItem(1).active()).toBe(false);
751
752 expect(menu.shownItem(2)).toBe(undefined);
753 });
754
755 it('should be filterable (trimming = " p")', function () {
756 var menu = HintMenu.create("/p=", listMultiPrefix);
757 // menu._firstActive = true;
758
759 menu.limit(2);
760 expect(menu.show()).toBe(true);
761 menu._prefix.add(" ");
762 menu._entry.add(" ")
763 expect(menu.show()).toBe(true);
764 menu._prefix.add("p")
765 menu._entry.add("p")
766 expect(menu.alwaysEntryValue()).toBe(" p");
767 expect(menu.show()).toBe(true);
768 expect(menu.shownItem(0).name()).toEqual("PP");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200769 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual(
Leo Repp56904d22021-04-26 15:53:22 +0200770 "<strong><mark>P</mark><mark>P</mark></strong>"+
771 "<span><mark>P</mark>ersonal <mark>P</mark>ronoun</span>"
772 );
773 });
774
775
776
777 it('should ignore navigation with failing prefix', function () {
778 var menu = HintMenu.create("cnx/", list);
779 menu.limit(2);
780 expect(menu.show()).toBe(true);
781
782 menu.next();
783
784 expect(menu.prefix("exit").show()).toBe(true);
785 expect(menu.element().querySelector('li')).toBe(null);
786 expect(menu.shownItem(0)).toBeUndefined();
787 expect(menu._prefix.active()).toBe(true);
788
789 menu.next();
790 expect(menu._prefix.active()).toBe(false);
791 expect(menu._entry.active()).toBe(true);
792
793 menu.next();
794 expect(menu._prefix.active()).toBe(true);
795 expect(menu._entry.active()).toBe(false);
796
797 menu.prev();
798 expect(menu._prefix.active()).toBe(false);
799 expect(menu._entry.active()).toBe(true);
800
801 menu.prev();
802 expect(menu._prefix.active()).toBe(true);
803 expect(menu._entry.active()).toBe(false);
804
805 });
806
807 it('should be navigatable with prefix', function () {
808 var menu = HintMenu.create("cnx/", demolist);
809 menu._firstActive = true;
810
811 menu.limit(3);
812
813 expect(menu.show()).toBe(true);
814 expect(menu.prefix()).toEqual("");
815 expect(menu.alwaysEntryValue()).toEqual("");
816 expect(menu._prefix.active()).toEqual(false);
817 expect(menu._entry.active()).toEqual(false);
818
819 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200820 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200821 expect(menu.shownItem(0).active()).toBe(true);
822 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200823 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200824 expect(menu.shownItem(1).active()).toBe(false);
825 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200826 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200827 expect(menu.shownItem(2).active()).toBe(false);
828 expect(menu.shownItem(3)).toBe(undefined);
829 expect(menu._prefix.active()).toEqual(false);
830 expect(menu._entry.active()).toEqual(false);
831
832 menu._prefix.add('a');
833 menu._entry.add('a');
834 expect(menu._prefix.active()).toEqual(false);
835 expect(menu._entry.active()).toEqual(false);
836 expect(menu.show()).toBe(true);
837 expect(menu.prefix()).toEqual("a");
838 expect(menu.alwaysEntryValue()).toEqual("a");
839 expect(menu.shownItem(0).name()).toEqual("Autor");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200840 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200841
842 menu._prefix.add('u');
843 menu._entry.add('u');
844 expect(menu.show()).toBe(true);
845 expect(menu.prefix()).toEqual("au");
846 expect(menu.alwaysEntryValue()).toEqual("au");
847 expect(menu.shownItem(0).name()).toEqual("Autor");
848 expect(menu._prefix.active()).toEqual(false);
849 expect(menu._entry.active()).toEqual(false);
Leo Repp7b0fbf92021-07-14 11:25:59 +0200850 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong><mark>Au</mark>tor</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200851
852 menu._prefix.chop();
853 menu._entry.chop();
854 expect(menu.show()).toBe(true);
855 expect(menu.prefix()).toEqual("a");
856 expect(menu.alwaysEntryValue()).toEqual("a");
857 expect(menu.shownItem(0).name()).toEqual("Autor");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200858 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200859
860 menu._prefix.chop();
861 menu._entry.chop();
862 expect(menu.show()).toBe(true);
863 expect(menu.prefix()).toEqual("");
864 expect(menu.alwaysEntryValue()).toEqual("");
865 expect(menu._prefix.active()).toEqual(false);
866 expect(menu._entry.active()).toEqual(false);
867 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200868 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200869 expect(menu.shownItem(0).active()).toBe(true);
870 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200871 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200872 expect(menu.shownItem(1).active()).toBe(false);
873 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200874 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200875 expect(menu.shownItem(2).active()).toBe(false);
876 expect(menu.shownItem(3)).toBe(undefined);
877
878 // Forward
879 menu._prefix.chop();
880 menu._entry.chop();
881 expect(menu.show()).toBe(true);
882 expect(menu.prefix()).toEqual("");
883 expect(menu._prefix.active()).toEqual(false);
884 expect(menu._entry.active()).toEqual(false);
885 expect(menu.alwaysEntryValue()).toEqual("");
886 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200887 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200888 expect(menu.shownItem(0).active()).toBe(true);
889 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200890 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200891 expect(menu.shownItem(1).active()).toBe(false);
892 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200893 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200894 expect(menu.shownItem(2).active()).toBe(false);
895
896 // Forward
897 menu.next();
898 expect(menu.prefix()).toEqual("");
899 expect(menu.alwaysEntryValue()).toEqual("");
900 expect(menu._prefix.active()).toEqual(false);
901 expect(menu._entry.active()).toEqual(false);
902 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200903 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200904 expect(menu.shownItem(0).active()).toBe(false);
905 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200906 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200907 expect(menu.shownItem(1).active()).toBe(true);
908 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200909 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200910 expect(menu.shownItem(2).active()).toBe(false);
911 expect(menu.shownItem(3)).toBe(undefined);
912
913 // Forward
914 menu.next();
915 expect(menu.prefix()).toEqual("");
916 expect(menu.alwaysEntryValue()).toEqual("");
917 expect(menu._prefix.active()).toEqual(false);
918 expect(menu._entry.active()).toEqual(false);
919 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200920 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200921 expect(menu.shownItem(0).active()).toBe(false);
922 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200923 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200924 expect(menu.shownItem(1).active()).toBe(false);
925 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200926 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200927 expect(menu.shownItem(2).active()).toBe(true);
928 expect(menu.shownItem(3)).toBe(undefined);
929
930 // Forward
931 menu.next();
932 expect(menu.prefix()).toEqual("");
933 expect(menu.alwaysEntryValue()).toEqual("");
934 expect(menu.shownItem(0).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200935 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Untertitel</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200936 expect(menu.shownItem(0).active()).toBe(false);
937 expect(menu.shownItem(1).name()).toEqual("Veröffentlichungsdatum");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200938 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200939 expect(menu.shownItem(1).active()).toBe(false);
940 expect(menu.shownItem(2).name()).toEqual("Länge");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200941 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Länge</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200942 expect(menu.shownItem(2).active()).toBe(true);
943 expect(menu.shownItem(3)).toBe(undefined);
944 expect(menu._prefix.active()).toEqual(false);
945 expect(menu._entry.active()).toEqual(false);
946
947 // Forward
948 menu.next();
949 expect(menu.prefix()).toEqual("");
950 expect(menu.alwaysEntryValue()).toEqual("");
951 expect(menu.shownItem(0).name()).toEqual("Veröffentlichungsdatum");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200952 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200953 expect(menu.shownItem(0).active()).toBe(false);
954 expect(menu.shownItem(1).name()).toEqual("Länge");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200955 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Länge</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200956 expect(menu.shownItem(1).active()).toBe(false);
957 expect(menu.shownItem(2).name()).toEqual("Autor");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200958 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Autor</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200959 expect(menu.shownItem(2).active()).toBe(true);
960 expect(menu.shownItem(3)).toBe(undefined);
961 expect(menu._prefix.active()).toEqual(false);
962 expect(menu._entry.active()).toEqual(false);
963
964 // Forward
965 menu.next();
966 expect(menu.prefix()).toEqual("");
967 expect(menu.alwaysEntryValue()).toEqual("");
968 expect(menu.shownItem(0).name()).toEqual("Veröffentlichungsdatum");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200969 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200970 expect(menu.shownItem(0).active()).toBe(false);
971 expect(menu.shownItem(1).name()).toEqual("Länge");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200972 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Länge</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200973 expect(menu.shownItem(1).active()).toBe(false);
974 expect(menu.shownItem(2).name()).toEqual("Autor");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200975 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Autor</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200976 expect(menu.shownItem(2).active()).toBe(false);
977 expect(menu.shownItem(3)).toBe(undefined);
978 expect(menu._prefix.active()).toEqual(false);
979 expect(menu._entry.active()).toEqual(true);
980
981 // Forward
982 menu.next();
983 expect(menu.prefix()).toEqual("");
984 expect(menu.alwaysEntryValue()).toEqual("");
985 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200986 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200987 expect(menu.shownItem(0).active()).toBe(true);
988 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200989 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200990 expect(menu.shownItem(1).active()).toBe(false);
991 expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum");
Leo Repp7b0fbf92021-07-14 11:25:59 +0200992 expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>");
Leo Repp56904d22021-04-26 15:53:22 +0200993 expect(menu.shownItem(2).active()).toBe(false);
994 });
995
996
997 it('should be navigatable with a prefix (1)', function () {
998 var menu = HintMenu.create("cnx/", demolist);
999 menu._firstActive = true;
1000
1001 menu.limit(3);
1002
1003 expect(menu.show()).toBe(true);
1004 expect(menu.prefix()).toEqual("");
1005 expect(menu.alwaysEntryValue()).toEqual("");
1006
1007 // Add prefix in uppercase - but check in lowercase
1008 menu.prefix('El');
1009 menu.alwaysEntryValue('El');
1010 expect(menu.show()).toBe(true);
1011
1012 expect(menu.prefix()).toEqual("El");
1013 expect(menu._prefix.active()).toEqual(false);
1014 expect(menu.alwaysEntryValue()).toEqual("El");
1015 expect(menu._entry.active()).toEqual(false);
1016 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001017 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001018 expect(menu.shownItem(0).active()).toBe(true);
1019 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001020 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001021 expect(menu.shownItem(1).active()).toBe(false);
1022 expect(menu.shownItem(2)).toBe(undefined);
1023
1024 // Forward
1025 menu.next();
1026 expect(menu.prefix()).toEqual("El");
1027 expect(menu._prefix.active()).toEqual(false);
1028 expect(menu.alwaysEntryValue()).toEqual("El");
1029 expect(menu._entry.active()).toEqual(false);
1030 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001031 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001032 expect(menu.shownItem(0).active()).toBe(false);
1033 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001034 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001035 expect(menu.shownItem(1).active()).toBe(true);
1036 expect(menu.shownItem(2)).toBe(undefined);
1037
1038 // Forward
1039 menu.next();
1040 expect(menu.prefix()).toEqual("El");
1041 expect(menu._prefix.active()).toEqual(true);
1042 expect(menu.alwaysEntryValue()).toEqual("El");
1043 expect(menu._entry.active()).toEqual(false);
1044 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001045 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001046 expect(menu.shownItem(0).active()).toBe(false);
1047 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001048 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001049 expect(menu.shownItem(1).active()).toBe(false);
1050 expect(menu.shownItem(2)).toBe(undefined);
1051
1052 // Forward
1053 menu.next();
1054 expect(menu.prefix()).toEqual("El");
1055 expect(menu._prefix.active()).toEqual(false);
1056 expect(menu.alwaysEntryValue()).toEqual("El");
1057 expect(menu._entry.active()).toEqual(true);
1058 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001059 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001060 expect(menu.shownItem(0).active()).toBe(false);
1061 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001062 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001063 expect(menu.shownItem(1).active()).toBe(false);
1064 expect(menu.shownItem(2)).toBe(undefined);
1065
1066 menu.prev()
1067 expect(menu.prefix()).toEqual("El");
1068 expect(menu._prefix.active()).toEqual(true);
1069 expect(menu.alwaysEntryValue()).toEqual("El");
1070 expect(menu._entry.active()).toEqual(false);
1071 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001072 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001073 expect(menu.shownItem(0).active()).toBe(false);
1074 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001075 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001076 expect(menu.shownItem(1).active()).toBe(false);
1077 expect(menu.shownItem(2)).toBe(undefined);
1078
1079 // Backward
1080 menu.prev();
1081 expect(menu.prefix()).toEqual("El");
1082 expect(menu._prefix.active()).toEqual(false);
1083 expect(menu.alwaysEntryValue()).toEqual("El");
1084 expect(menu._entry.active()).toEqual(false);
1085 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001086 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001087 expect(menu.shownItem(0).active()).toBe(false);
1088
1089 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001090 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001091 expect(menu.shownItem(1).active()).toBe(true);
1092 expect(menu.shownItem(2)).toBe(undefined);
1093 });
1094
1095
1096 it('should be navigatable with a prefix (2)', function () {
1097 var menu = HintMenu.create("cnx/", demolist);
1098 menu._firstActive = true;
1099
1100 menu.limit(3);
1101 expect(menu.show()).toBe(true);
1102 expect(menu.prefix()).toEqual("");
1103 menu.prefix('el');
1104 expect(menu.alwaysEntryValue()).toEqual("");
1105 menu.alwaysEntryValue('el');
1106 expect(menu.show()).toBe(true);
1107
1108 expect(menu.prefix()).toEqual("el");
1109 expect(menu._prefix.active()).toEqual(false);
1110 expect(menu.alwaysEntryValue()).toEqual("el");
1111 expect(menu._entry.active()).toEqual(false);
1112 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001113 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001114 expect(menu.shownItem(0).active()).toBe(true);
1115 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001116 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001117 expect(menu.shownItem(1).active()).toBe(false);
1118 expect(menu.shownItem(2)).toBe(undefined);
1119
1120 // Backward
1121 menu.prev();
1122 expect(menu._prefix.active()).toEqual(false);
1123 expect(menu._entry.active()).toEqual(true);
1124
1125 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001126 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001127 expect(menu.shownItem(0).active()).toBe(false);
1128
1129 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001130 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001131 expect(menu.shownItem(1).active()).toBe(false);
1132 expect(menu.shownItem(2)).toBe(undefined);
1133
1134
1135 // Backward
1136 menu.prev();
1137 expect(menu._prefix.active()).toEqual(true);
1138 expect(menu._entry.active()).toEqual(false);
1139
1140 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001141 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001142 expect(menu.shownItem(0).active()).toBe(false);
1143
1144 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001145 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001146 expect(menu.shownItem(1).active()).toBe(false);
1147 expect(menu.shownItem(2)).toBe(undefined);
1148
1149 // Backward
1150 menu.prev();
1151 expect(menu._prefix.active()).toEqual(false);
1152 expect(menu._entry.active()).toEqual(false);
1153 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001154 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001155 expect(menu.shownItem(0).active()).toBe(false);
1156 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001157 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001158 expect(menu.shownItem(1).active()).toBe(true);
1159 expect(menu.shownItem(2)).toBe(undefined);
1160 });
1161
1162 it('should be navigatable with a prefix (3)', function () {
1163 var menu = HintMenu.create("cnx/", demolist);
1164 menu._firstActive = true;
1165 menu.limit(3);
1166 expect(menu.show()).toBe(true);
1167 expect(menu.prefix()).toEqual("");
1168 menu.prefix('el');
1169 expect(menu.alwaysEntryValue()).toEqual("");
1170 expect(menu.alwaysEntry().value()).toEqual("");
1171 menu.alwaysEntryValue('el');
1172 expect(menu.show()).toBe(true);
1173
1174 expect(menu.prefix()).toEqual("el");
1175 expect(menu._prefix.active()).toEqual(false);
1176 expect(menu.alwaysEntry().value()).toEqual("el");
1177 expect(menu._entry.active()).toEqual(false);
1178 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001179 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001180 expect(menu.shownItem(0).active()).toBe(true);
1181 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001182 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001183 expect(menu.shownItem(1).active()).toBe(false);
1184 expect(menu.shownItem(2)).toBe(undefined);
1185
1186 // Backward
1187 menu.prev();
1188 expect(menu._prefix.active()).toEqual(false);
1189 expect(menu._entry.active()).toEqual(true);
1190 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001191 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001192 expect(menu.shownItem(0).active()).toBe(false);
1193 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001194 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001195 expect(menu.shownItem(1).active()).toBe(false);
1196 expect(menu.shownItem(2)).toBe(undefined);
1197
1198 // Backward
1199 menu.prev();
1200 expect(menu._prefix.active()).toEqual(true);
1201 expect(menu._entry.active()).toEqual(false);
1202 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001203 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001204 expect(menu.shownItem(0).active()).toBe(false);
1205 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001206 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001207 expect(menu.shownItem(1).active()).toBe(false);
1208 expect(menu.shownItem(2)).toBe(undefined);
1209
1210
1211 // Forward
1212 menu.next();
1213 expect(menu.prefix()).toEqual("el");
1214 expect(menu._prefix.active()).toEqual(false);
1215 expect(menu._entry.active()).toEqual(true);
1216 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001217 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001218 expect(menu.shownItem(0).active()).toBe(false);
1219 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001220 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001221 expect(menu.shownItem(1).active()).toBe(false);
1222 expect(menu.shownItem(2)).toBe(undefined);
1223
1224 // Forward
1225 menu.next();
1226 expect(menu.prefix()).toEqual("el");
1227 expect(menu._prefix.active()).toEqual(false);
1228 expect(menu._entry.active()).toEqual(false);
1229 expect(menu.shownItem(0).name()).toEqual("Titel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001230 expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001231 expect(menu.shownItem(0).active()).toBe(true);
1232 expect(menu.shownItem(1).name()).toEqual("Untertitel");
Leo Repp7b0fbf92021-07-14 11:25:59 +02001233 expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>");
Leo Repp56904d22021-04-26 15:53:22 +02001234 expect(menu.shownItem(1).active()).toBe(false);
1235 expect(menu.shownItem(2)).toBe(undefined);
1236 });
1237
1238
1239
1240 xit('should scroll to a chosen value after prefixing, if the chosen value is live');
1241 });
1242
1243 describe('KorAP.AlwaysMenu.Entry', function () {
1244 it('should be initializable', function () {
1245 var p = alwaysEntryClass.create();
marcrusian235a23a2021-05-26 14:28:11 +02001246 expect(p.element().classList.contains('pref')).toBeFalsy();
1247 expect(p.element().classList.contains('entry')).toBeTruthy();
Leo Repp56904d22021-04-26 15:53:22 +02001248 expect(p.isSet()).not.toBeTruthy();
1249 expect(p.element().innerHTML).toEqual("Speichern");
1250 expect(p.value()).toEqual("");
1251
1252 /*
1253 expect(mi.lcField()).toEqual(' baum');
1254 */
1255
1256 });
1257
1258 it('should be initializable with a different name', function () {
1259 var p = alwaysEntryClass.create("Save");
marcrusian235a23a2021-05-26 14:28:11 +02001260 expect(p.element().classList.contains('pref')).toBeFalsy();
1261 expect(p.element().classList.contains('entry')).toBeTruthy();
Leo Repp56904d22021-04-26 15:53:22 +02001262 expect(p.isSet()).not.toBeTruthy();
1263 expect(p.element().innerHTML).toEqual("Save");
1264 expect(p.value()).toEqual("");
1265
1266 /*
1267 expect(mi.lcField()).toEqual(' baum');
1268 */
1269
1270 });
1271
1272 it('should be modifiable', function () {
1273 var p = alwaysEntryClass.create();
1274 expect(p.value()).toEqual('');
1275 expect(p.element().firstChild).toEqual(document.createTextNode("Speichern"));
1276
1277 // Set string
1278 expect(p.value('Test')).toEqual('Test');
1279 expect(p.value()).toEqual('Test');
1280 expect(p.element().firstChild.nodeValue).toEqual('Speichern');
1281
1282 // Add string
1283 expect(p.add('ified')).toEqual('Testified');
1284 expect(p.value()).toEqual('Testified');
1285 expect(p.element().firstChild.nodeValue).toEqual('Speichern');
1286
1287 // Clear string
1288 p.clear();
1289 expect(p.value()).toEqual('');
1290 expect(p.element().firstChild).toEqual(document.createTextNode("Speichern"));
1291
1292 // Set string
1293 expect(p.value('Test')).toEqual('Test');
1294 expect(p.value()).toEqual('Test');
1295 expect(p.element().firstChild.nodeValue).toEqual('Speichern');
1296
1297 expect(p.chop()).toEqual('Tes');
1298 expect(p.value()).toEqual('Tes');
1299 expect(p.element().firstChild.nodeValue).toEqual('Speichern');
1300
1301 expect(p.chop()).toEqual('Te');
1302 expect(p.value()).toEqual('Te');
1303 expect(p.element().firstChild.nodeValue).toEqual('Speichern');
1304
1305 expect(p.chop()).toEqual('T');
1306 expect(p.value()).toEqual('T');
1307 expect(p.element().firstChild.nodeValue).toEqual('Speichern');
1308
1309 expect(p.chop()).toEqual('');
1310 expect(p.value()).toEqual('');
1311 expect(p.element().firstChild).toEqual(document.createTextNode("Speichern"));
1312 });
1313
1314 it('should be activatable', function () {
1315 var p = alwaysEntryClass.create();
1316 expect(p.value()).toEqual('');
1317 expect(p.element().firstChild).toEqual(document.createTextNode("Speichern"));
1318
1319 expect(p.value('Test')).toEqual('Test');
1320 expect(p.element().firstChild.nodeValue).toEqual('Speichern');
1321
1322 expect(p.active()).not.toBeTruthy();
1323 expect(p.element().classList.contains('active')).not.toBeTruthy();
1324
1325 p.active(true);
1326 expect(p.active()).toBeTruthy();
1327 expect(p.element().classList.contains('active')).toBeTruthy();
1328 });
1329 });
1330
1331 describe('KorAP.AlwaysMenu.Slider', function () {
1332
1333 var demolonglist = [
1334 ['Titel', 'title'],
1335 ['Untertitel', 'subTitle'],
1336 ['Veröffentlichungsdatum', 'pubDate'],
1337 ['Länge', 'length'],
1338 ['Autor', 'author'],
1339 ['Genre', 'genre'],
1340 ['corpusID', 'corpusID'],
1341 ['docID', 'docID'],
1342 ['textID', 'textID'],
1343 ];
1344
1345 it('should correctly be initializable', function () {
1346 var list = [
1347 ["Constituency"],
1348 ["Lemma"],
1349 ["Morphology"],
1350 ["Part-of-Speech"],
1351 ["Syntax"]
1352 ];
1353
1354 var menu = OwnAlwaysMenu.create(list);
1355
1356 menu._firstActive = true;
1357 menu.limit(3);
1358
1359 expect(menu.show()).toBe(true);
1360
1361 expect(menu.shownItem(0).active()).toBe(true);
1362 expect(menu.shownItem(1).active()).toBe(false);
1363 expect(menu.shownItem(2).active()).toBe(false);
1364 expect(menu.slider().offset()).toEqual(0);
1365 expect(menu.position).toEqual(0);
1366 });
1367
1368 it('should correctly move on arrow keys', function () {
1369 var list = [
1370 ["Constituency"],
1371 ["Lemma"],
1372 ["Morphology"],
1373 ["Part-of-Speech"],
1374 ["Syntax"]
1375 ];
1376
1377 var menu = OwnAlwaysMenu.create(list);
1378
1379 menu._firstActive = true;
1380 menu.limit(3);
1381
1382 expect(menu.show()).toBe(true);
1383
1384 menu.next();
1385 expect(menu.shownItem(0).active()).toBe(false);
1386 expect(menu.shownItem(1).active()).toBe(true);
1387 expect(menu.shownItem(2).active()).toBe(false);
1388 expect(menu._prefix.active()).toBe(false);
1389 expect(menu._entry.active()).toBe(false);
1390 expect(menu.slider().offset()).toEqual(0);
1391 expect(menu.position).toEqual(1);
1392
1393 menu.next();
1394 expect(menu.shownItem(0).active()).toBe(false);
1395 expect(menu.shownItem(1).active()).toBe(false);
1396 expect(menu.shownItem(2).active()).toBe(true);
1397 expect(menu._prefix.active()).toBe(false);
1398 expect(menu._entry.active()).toBe(false);
1399 expect(menu.slider().offset()).toEqual(0);
1400 expect(menu.position).toEqual(2);
1401
1402 menu.next();
1403 expect(menu.shownItem(0).active()).toBe(false);
1404 expect(menu.shownItem(1).active()).toBe(false);
1405 expect(menu.shownItem(2).active()).toBe(true);
1406 expect(menu._prefix.active()).toBe(false);
1407 expect(menu._entry.active()).toBe(false);
1408 expect(menu.slider().offset()).toEqual(1);
1409 expect(menu.position).toEqual(3);
1410
1411 menu.next();
1412 expect(menu.shownItem(0).active()).toBe(false);
1413 expect(menu.shownItem(1).active()).toBe(false);
1414 expect(menu.shownItem(2).active()).toBe(true);
1415 expect(menu._prefix.active()).toBe(false);
1416 expect(menu._entry.active()).toBe(false);
1417 expect(menu.slider().offset()).toEqual(2);
1418 expect(menu.position).toEqual(4);
1419
1420 menu.next();
1421 expect(menu.shownItem(0).active()).toBe(false);
1422 expect(menu.shownItem(1).active()).toBe(false);
1423 expect(menu.shownItem(2).active()).toBe(false);
1424 expect(menu._prefix.active()).toBe(false);
1425 expect(menu._entry.active()).toBe(true);
1426 expect(menu.slider().offset()).toEqual(2);
1427 expect(menu.position).toEqual(7);
1428
1429 menu.next();
1430 expect(menu.shownItem(0).active()).toBe(true);
1431 expect(menu.shownItem(1).active()).toBe(false);
1432 expect(menu.shownItem(2).active()).toBe(false);
1433 expect(menu._prefix.active()).toBe(false);
1434 expect(menu._entry.active()).toBe(false);
1435 expect(menu.slider().offset()).toEqual(0);
1436 expect(menu.position).toEqual(0);
1437
1438 expect(menu.slider()._slider.style.height).toEqual('60%');
1439 });
1440
1441 });
1442
1443 describe('KorAP.AlwaysMenu.Benchmark', function () {
1444 var menu = alwaysMenuClass.create([
1445 ['Titel', 'title'],
1446 ['Untertitel', 'subTitle'],
1447 ['Veröffentlichungsdatum', 'pubDate'],
1448 ['Länge', 'length'],
1449 ['Autor', 'author']
1450 ]);
1451
1452 menu.limit(3).show();
1453
1454 // Some actions
1455 menu.next();
1456 menu.next();
1457 menu.prev();
1458 menu.prev();
1459 menu.prev();
1460
1461 menu.pageDown();
1462 menu.pageUp();
1463
1464 // There is no fourth item in the list!
1465 menu.prefix('e').show(4);
1466 menu.next();
1467 menu.next();
1468 menu.prev();
1469 menu.prev();
1470 menu.prev();
1471 });
1472 });