Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1 | define( |
| 2 | ['menu', 'menu/item', 'menu/prefix', 'menu/lengthField'], |
| 3 | function (menuClass, menuItemClass, prefixClass, lengthFieldClass) { |
Akron | 1ff3ac2 | 2016-04-28 16:30:45 +0200 | [diff] [blame] | 4 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 5 | // The OwnMenu item |
| 6 | KorAP.OwnMenuItem = { |
| 7 | create : function (params) { |
| 8 | return Object.create(menuItemClass).upgradeTo(KorAP.OwnMenuItem)._init(params); |
| 9 | }, |
| 10 | content : function (content) { |
| 11 | if (arguments.length === 1) { |
| 12 | this._content = content; |
| 13 | }; |
| 14 | return this._content; |
| 15 | }, |
| 16 | _init : function (params) { |
| 17 | if (params[0] === undefined) |
| 18 | throw new Error("Missing parameters"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 19 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 20 | this._content = document.createTextNode(params[0]); |
| 21 | this._lcField = ' ' + this.content().textContent.toLowerCase(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 22 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 23 | return this; |
| 24 | } |
| 25 | }; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 26 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 27 | // The OwnMenu |
| 28 | KorAP.OwnMenu = { |
| 29 | create : function (list) { |
| 30 | return Object.create(menuClass) |
| 31 | .upgradeTo(KorAP.OwnMenu) |
| 32 | ._init(list, { itemClass : KorAP.OwnMenuItem }); |
| 33 | } |
| 34 | }; |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 35 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 36 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 37 | // HintMenuItem |
| 38 | KorAP.HintMenuItem = { |
| 39 | create : function (params) { |
| 40 | return Object.create(menuItemClass) |
| 41 | .upgradeTo(KorAP.HintMenuItem) |
| 42 | ._init(params); |
| 43 | }, |
| 44 | content : function (content) { |
| 45 | if (arguments.length === 1) { |
| 46 | this._content = content; |
| 47 | }; |
| 48 | return this._content; |
| 49 | }, |
| 50 | _init : function (params) { |
| 51 | if (params[0] === undefined || params[1] === undefined) |
| 52 | throw new Error("Missing parameters"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 53 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 54 | this._name = params[0]; |
| 55 | this._action = params[1]; |
| 56 | this._lcField = ' ' + this._name.toLowerCase(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 57 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 58 | if (params.length > 2) { |
| 59 | this._desc = params[2]; |
| 60 | this._lcField += " " + this._desc.toLowerCase(); |
| 61 | }; |
| 62 | |
| 63 | return this; |
| 64 | }, |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 65 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 66 | name : function () { |
| 67 | return this._name; |
| 68 | }, |
| 69 | action : function () { |
| 70 | return this._action; |
| 71 | }, |
| 72 | desc : function () { |
| 73 | return this._desc; |
| 74 | }, |
| 75 | element : function () { |
| 76 | // already defined |
Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 77 | if (this._el !== undefined) |
| 78 | return this._el; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 79 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 80 | // Create list item |
| 81 | var li = document.createElement("li"); |
| 82 | li.setAttribute("data-action", this._action); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 83 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 84 | // Create title |
| 85 | var name = document.createElement("strong"); |
| 86 | name.appendChild(document.createTextNode(this._name)); |
| 87 | |
| 88 | li.appendChild(name); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 89 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 90 | // Create description |
| 91 | if (this._desc !== undefined) { |
| 92 | var desc = document.createElement("span"); |
| 93 | desc.appendChild(document.createTextNode(this._desc)); |
| 94 | li.appendChild(desc); |
| 95 | }; |
Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 96 | return this._el = li; |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 97 | } |
| 98 | }; |
| 99 | |
| 100 | |
| 101 | // HintMenu |
| 102 | KorAP.HintMenu = { |
| 103 | create : function (context, list) { |
| 104 | var obj = Object.create(menuClass) |
| 105 | .upgradeTo(KorAP.HintMenu) |
| 106 | ._init(list, {itemClass : KorAP.HintMenuItem}); |
| 107 | obj._context = context; |
| 108 | return obj; |
| 109 | } |
| 110 | }; |
| 111 | |
| 112 | |
| 113 | // The ComplexMenuItem |
| 114 | KorAP.ComplexMenuItem = { |
| 115 | create : function (params) { |
| 116 | return Object.create(menuItemClass) |
| 117 | .upgradeTo(KorAP.ComplexMenuItem) |
| 118 | ._init(params); |
| 119 | }, |
| 120 | content : function (content) { |
| 121 | if (arguments.length === 1) { |
| 122 | this._content = content; |
| 123 | }; |
| 124 | return this._content; |
| 125 | }, |
| 126 | _init : function (params) { |
| 127 | if (params[0] === undefined) |
| 128 | throw new Error("Missing parameters"); |
| 129 | |
| 130 | var r = document.createElement('div'); |
| 131 | for (var i = 1; i <= params.length; i++) { |
| 132 | var h = document.createElement('h' + i); |
| 133 | h.appendChild(document.createTextNode(params[i-1])); |
| 134 | r.appendChild(h); |
| 135 | }; |
| 136 | |
| 137 | this._content = r; |
| 138 | this._lcField = ' ' + this.content().textContent.toLowerCase(); |
| 139 | |
| 140 | return this; |
| 141 | } |
| 142 | }; |
| 143 | |
| 144 | |
| 145 | describe('KorAP.MenuItem', function () { |
| 146 | it('should be initializable', function () { |
| 147 | expect( |
| 148 | function() { menuItemClass.create([]) } |
| 149 | ).toThrow(new Error("Missing parameters")); |
| 150 | |
| 151 | expect( |
| 152 | function() { KorAP.OwnMenuItem.create([]) } |
| 153 | ).toThrow(new Error("Missing parameters")); |
| 154 | |
| 155 | var mi = KorAP.OwnMenuItem.create(["Baum"]); |
| 156 | expect(mi.element().firstChild.nodeValue).toEqual('Baum'); |
| 157 | expect(mi.lcField()).toEqual(' baum'); |
| 158 | }); |
| 159 | |
| 160 | it('shouldn\'t have a reference to the menu', function () { |
| 161 | var menuItem = KorAP.OwnMenuItem.create(['Test']); |
| 162 | expect(menuItem.menu()).toBe(undefined); |
| 163 | }); |
| 164 | |
| 165 | it('should be activatable and deactivateable by class', function () { |
| 166 | var menuItem = KorAP.OwnMenuItem.create(['Test']); |
| 167 | |
| 168 | expect(menuItem.active()).toBe(false); |
| 169 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 170 | menuItem.active(true); |
| 171 | expect(menuItem.active()).toBe(true); |
| 172 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
| 173 | menuItem.active(false); // Is active |
| 174 | expect(menuItem.active()).toBe(false); |
| 175 | expect(menuItem.element().getAttribute("class")).toEqual(""); |
| 176 | menuItem.active(true); |
| 177 | expect(menuItem.active()).toBe(true); |
| 178 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
| 179 | |
| 180 | menuItem = KorAP.OwnMenuItem.create(['Spiegel']); |
| 181 | expect(menuItem.active()).toBe(false); |
| 182 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 183 | menuItem.active(false); // Is not active |
| 184 | expect(menuItem.active()).toBe(false); |
| 185 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 186 | }); |
| 187 | |
| 188 | it('should be set to boundary', function () { |
| 189 | var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']); |
| 190 | expect(menuItem.active()).toBe(false); |
| 191 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 192 | |
| 193 | // Set active |
| 194 | menuItem.active(true); |
| 195 | expect(menuItem.active()).toBe(true); |
| 196 | expect(menuItem.noMore()).toBe(false); |
| 197 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
| 198 | |
| 199 | // Set no more |
| 200 | menuItem.noMore(true); |
| 201 | expect(menuItem.active()).toBe(true); |
| 202 | expect(menuItem.noMore()).toBe(true); |
| 203 | expect(menuItem.element().getAttribute("class")).toEqual("active no-more"); |
| 204 | |
| 205 | // No no more |
| 206 | menuItem.noMore(false); |
| 207 | expect(menuItem.active()).toBe(true); |
| 208 | expect(menuItem.noMore()).toBe(false); |
| 209 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
| 210 | |
| 211 | // Set no more, deactivate |
| 212 | menuItem.noMore(true); |
| 213 | menuItem.active(false); |
| 214 | expect(menuItem.active()).toBe(false); |
| 215 | expect(menuItem.noMore()).toBe(true); |
| 216 | expect(menuItem.element().getAttribute("class")).toEqual("no-more"); |
| 217 | |
| 218 | // Set active |
| 219 | menuItem.active(true); |
| 220 | expect(menuItem.active()).toBe(true); |
| 221 | expect(menuItem.noMore()).toBe(true); |
| 222 | expect(menuItem.element().getAttribute("class")).toEqual("no-more active"); |
| 223 | }); |
| 224 | |
| 225 | |
| 226 | it('should be highlightable', function () { |
| 227 | // Highlight in the middle |
| 228 | var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']); |
| 229 | menuItem.highlight("ren"); |
| 230 | expect(menuItem.element().innerHTML).toEqual("Co<mark>reN</mark>LP"); |
| 231 | |
| 232 | menuItem.lowlight(); |
| 233 | expect(menuItem.element().innerHTML).toEqual("CoreNLP"); |
| 234 | |
| 235 | var plain = "<div><h1>CoreNLP</h1><h2>corenlp/</h2></div>"; |
| 236 | |
| 237 | // Starting highlight |
| 238 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']); |
| 239 | menuItem.highlight("cor"); |
| 240 | expect(menuItem.element().innerHTML).toEqual("<div><h1><mark>Cor</mark>eNLP</h1><h2><mark>cor</mark>enlp/</h2></div>"); |
| 241 | |
| 242 | menuItem.lowlight(); |
| 243 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 244 | |
| 245 | // Starting highlight - short |
| 246 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']); |
| 247 | menuItem.highlight("c"); |
| 248 | expect(menuItem.element().innerHTML).toEqual("<div><h1><mark>C</mark>oreNLP</h1><h2><mark>c</mark>orenlp/</h2></div>"); |
| 249 | |
| 250 | menuItem.lowlight(); |
| 251 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 252 | |
| 253 | // Highlight at the end |
| 254 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']); |
| 255 | menuItem.highlight("nlp"); |
| 256 | expect(menuItem.element().innerHTML).toEqual("<div><h1>Core<mark>NLP</mark></h1><h2>core<mark>nlp</mark>/</h2></div>"); |
| 257 | |
| 258 | menuItem.lowlight(); |
| 259 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 260 | |
| 261 | // Highlight at the end - short |
| 262 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']); |
| 263 | menuItem.highlight("p"); |
| 264 | expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNL<mark>P</mark></h1><h2>corenl<mark>p</mark>/</h2></div>"); |
| 265 | |
| 266 | menuItem.lowlight(); |
| 267 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 268 | |
| 269 | // No highlight |
| 270 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']); |
| 271 | menuItem.highlight("xp"); |
| 272 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 273 | |
| 274 | menuItem.lowlight(); |
| 275 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 276 | |
| 277 | // Highlight in the middle - first |
| 278 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 279 | menuItem.highlight("ren"); |
| 280 | expect(menuItem.element().innerHTML).toEqual("<div><h1>Co<mark>reN</mark>LP</h1><h2>co<mark>ren</mark>lp/</h2><h3>This is my Example</h3></div>"); |
| 281 | |
| 282 | plain = "<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Example</h3></div>" |
| 283 | |
| 284 | menuItem.lowlight(); |
| 285 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 286 | |
| 287 | // Highlight in the middle - second |
| 288 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 289 | menuItem.highlight("ampl"); |
| 290 | expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Ex<mark>ampl</mark>e</h3></div>"); |
| 291 | |
| 292 | menuItem.lowlight(); |
| 293 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 294 | |
| 295 | // Highlight in the middle - both |
| 296 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 297 | menuItem.highlight("e"); |
Akron | acffc65 | 2017-12-18 21:21:25 +0100 | [diff] [blame] | 298 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 299 | expect(menuItem.element().innerHTML).toEqual("<div><h1>Cor<mark>e</mark>NLP</h1><h2>cor<mark>e</mark>nlp/</h2><h3>This is my <mark>E</mark>xampl<mark>e</mark></h3></div>"); |
| 300 | |
| 301 | menuItem.lowlight(); |
| 302 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 303 | |
| 304 | // Highlight in the end - second |
| 305 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 306 | menuItem.highlight("le"); |
| 307 | expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Examp<mark>le</mark></h3></div>"); |
| 308 | |
| 309 | menuItem.lowlight(); |
| 310 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 311 | |
| 312 | // Highlight at the beginning - second |
| 313 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 314 | menuItem.highlight("this"); |
| 315 | expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3><mark>This</mark> is my Example</h3></div>"); |
| 316 | |
| 317 | menuItem.lowlight(); |
| 318 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 319 | }); |
| 320 | }); |
| 321 | |
| 322 | |
| 323 | describe('KorAP.Menu', function () { |
| 324 | var list = [ |
| 325 | ["Constituency", "c=", "Example 1"], |
| 326 | ["Lemma", "l="], |
| 327 | ["Morphology", "m=", "Example 2"], |
| 328 | ["Part-of-Speech", "p="], |
| 329 | ["Syntax", "syn="] |
| 330 | ]; |
| 331 | |
Akron | acffc65 | 2017-12-18 21:21:25 +0100 | [diff] [blame] | 332 | var listMultiPrefix = [ |
| 333 | ["PP","PP ","Personal Pronoun"], |
| 334 | ["PPP","PPP ","Personal Pronoun, Plural"], |
| 335 | ["PPPA","PPPA ","Personal Pronoun, Plural, Acc."], |
| 336 | ["PPPD","PPPD ","Personal Pronoun, Plural, Dative"], |
| 337 | ["PPPR","PPPR ","Personal Pronoun, Plural, Direct"], |
| 338 | ["PPPO","PPPO ","Personal Pronoun, Plural, Oblique"], |
| 339 | ["PPS","PPS ","Personal Pronoun, Singular"], |
| 340 | ["PPSA","PPSA ","Personal Pronoun, Singular, Accusative"], |
| 341 | ["PPSD","PPSD ","Personal Pronoun, Singular, Dative"], |
| 342 | ["PPSR","PPSR ","Personal Pronoun, Singular, Direct"], |
| 343 | ["PPSN","PPSN ","Personal Pronoun, Singular, Nominative"], |
| 344 | ["PPSO","PPSO ","Personal Pronoun, Singular, Oblique"] |
| 345 | ]; |
| 346 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 347 | var demolist = [ |
| 348 | ['Titel', 'title'], |
| 349 | ['Untertitel', 'subTitle'], |
| 350 | ['Veröffentlichungsdatum', 'pubDate'], |
| 351 | ['Länge', 'length'], |
| 352 | ['Autor', 'author'] |
| 353 | ]; |
| 354 | |
| 355 | var demolonglist = [ |
| 356 | ['Titel', 'title'], |
| 357 | ['Untertitel', 'subTitle'], |
| 358 | ['Veröffentlichungsdatum', 'pubDate'], |
| 359 | ['Länge', 'length'], |
| 360 | ['Autor', 'author'], |
| 361 | ['Genre', 'genre'], |
| 362 | ['corpusID', 'corpusID'], |
| 363 | ['docID', 'docID'], |
| 364 | ['textID', 'textID'], |
| 365 | ]; |
| 366 | |
| 367 | it('should be initializable', function () { |
| 368 | var list = [ |
| 369 | ["Constituency"], |
| 370 | ["Lemma"], |
| 371 | ["Morphology"], |
| 372 | ["Part-of-Speech"], |
| 373 | ["Syntax"] |
| 374 | ]; |
| 375 | |
| 376 | var menu = KorAP.OwnMenu.create(list); |
hebasta | a780688 | 2019-11-18 19:35:47 +0100 | [diff] [blame] | 377 | expect(menu.dontHide).toBe(false); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 378 | menu._firstActive = true; |
| 379 | expect(menu.itemClass()).toEqual(KorAP.OwnMenuItem); |
| 380 | expect(menu.element().nodeName).toEqual('UL'); |
| 381 | expect(menu.element().classList.contains('visible')).toBeFalsy(); |
| 382 | expect(menu.limit()).toEqual(8); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 383 | expect(menu._notItemElements).toEqual(3); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 384 | |
| 385 | menu.limit(9); |
| 386 | expect(menu.limit()).toEqual(9); |
| 387 | |
| 388 | menu.limit(8); |
| 389 | |
| 390 | // view |
| 391 | menu.show(); |
| 392 | |
| 393 | // First element in list |
| 394 | expect(menu.item(0).active()).toBe(true); |
| 395 | expect(menu.item(0).noMore()).toBe(true); |
| 396 | |
| 397 | // Middle element in list |
| 398 | expect(menu.item(2).active()).toBe(false); |
| 399 | expect(menu.item(2).noMore()).toBe(false); |
| 400 | |
| 401 | // Last element in list |
| 402 | expect(menu.item(menu.length() - 1).active()).toBe(false); |
| 403 | expect(menu.item(menu.length() - 1).noMore()).toBe(true); |
| 404 | }); |
| 405 | |
| 406 | it('should have a reference to the menu', function () { |
| 407 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 408 | expect(menu.item(0).menu()).toEqual(menu); |
| 409 | |
| 410 | menu = KorAP.HintMenu.create("cnx/", list); |
| 411 | expect(menu.element().menu).toEqual(menu); |
| 412 | }); |
| 413 | |
| 414 | |
| 415 | it('should be visible', function () { |
| 416 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 417 | expect(menu.removeItems()).toBe(undefined); |
| 418 | menu.limit(3); |
| 419 | |
| 420 | expect(menu.show()).toBe(true); |
| 421 | |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 422 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
| 423 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
| 424 | expect(menu.directElementChildrenByTagName("li")[1].getAttribute("data-action")).toEqual("l="); |
| 425 | expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 426 | expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 427 | |
| 428 | // Check boundaries |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 429 | expect(menu.directElementChildrenByTagName("li")[0].classList.contains("no-more")).toBe(true); |
| 430 | expect(menu.directElementChildrenByTagName("li")[1].classList.contains("no-more")).toBe(false); |
| 431 | expect(menu.directElementChildrenByTagName("li")[2].classList.contains("no-more")).toBe(false); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 432 | }); |
| 433 | |
| 434 | it('should be filterable', function () { |
| 435 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 436 | menu.limit(3); |
| 437 | expect(menu.prefix("o").show()).toBe(true); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 438 | expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("o"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 439 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
| 440 | 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>"); |
| 441 | expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>"); |
| 442 | expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 443 | |
| 444 | // Check boundaries |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 445 | expect(menu.directElementChildrenByTagName("li")[0].classList.contains("no-more")).toBe(true); |
| 446 | expect(menu.directElementChildrenByTagName("li")[1].classList.contains("no-more")).toBe(false); |
| 447 | expect(menu.directElementChildrenByTagName("li")[2].classList.contains("no-more")).toBe(true); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 448 | |
| 449 | menu.limit(2); |
| 450 | |
| 451 | expect(menu.prefix("o").show()).toBe(true); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 452 | expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("o"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 453 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
| 454 | 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>"); |
| 455 | expect(menu.directElementChildrenByTagName("li")[2]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 456 | |
| 457 | // Check boundaries |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 458 | expect(menu.directElementChildrenByTagName("li")[0].classList.contains("no-more")).toBe(true); |
| 459 | expect(menu.directElementChildrenByTagName("li")[1].classList.contains("no-more")).toBe(false); |
| 460 | expect(menu.directElementChildrenByTagName("li")[2]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 461 | |
| 462 | expect(menu.prefix("e").show()).toBe(true); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 463 | expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("e"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 464 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
| 465 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
| 466 | expect(menu.directElementChildrenByTagName("li")[2]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 467 | |
| 468 | menu.limit(5); |
| 469 | expect(menu.prefix("a").show()).toBe(true); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 470 | expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("a"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 471 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Ex<mark>a</mark>mple 1</span>"); |
| 472 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Lemm<mark>a</mark></strong>"); |
| 473 | expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Ex<mark>a</mark>mple 2</span>"); |
| 474 | expect(menu.directElementChildrenByTagName("li")[3].innerHTML).toEqual("<strong>P<mark>a</mark>rt-of-Speech</strong>"); |
| 475 | expect(menu.directElementChildrenByTagName("li")[4].innerHTML).toEqual("<strong>Synt<mark>a</mark>x</strong>"); |
| 476 | expect(menu.directElementChildrenByTagName("li")[5]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 477 | }); |
| 478 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 479 | it('should be nextable', function () { |
| 480 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 481 | menu._firstActive = true; |
| 482 | |
| 483 | // Show only 3 items |
| 484 | menu.limit(3); |
| 485 | expect(menu.show()).toBe(true); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 486 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 487 | expect(menu.shownItem(0).active()).toBe(true); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 488 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 489 | expect(menu.shownItem(1).active()).toBe(false); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 490 | expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 491 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 492 | expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 493 | |
| 494 | // Activate next (1) |
| 495 | menu.next(); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 496 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 497 | expect(menu.shownItem(0).active()).toBe(false); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 498 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 499 | expect(menu.shownItem(1).active()).toBe(true); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 500 | expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 501 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 502 | expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 503 | |
| 504 | // Activate next (2) |
| 505 | menu.next(); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 506 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 507 | expect(menu.shownItem(0).active()).toBe(false); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 508 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 509 | expect(menu.shownItem(1).active()).toBe(false); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 510 | expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 511 | expect(menu.shownItem(2).active()).toBe(true); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 512 | expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 513 | |
| 514 | // Activate next (3) |
| 515 | // scroll! |
| 516 | menu.next(); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 517 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Lemma</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 518 | expect(menu.shownItem(0).active()).toBe(false); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 519 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 520 | expect(menu.shownItem(1).active()).toBe(false); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 521 | expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 522 | expect(menu.shownItem(2).active()).toBe(true); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 523 | expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 524 | |
| 525 | // Activate next (4) |
| 526 | menu.next(); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 527 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 528 | expect(menu.shownItem(0).active()).toBe(false); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 529 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 530 | expect(menu.shownItem(1).active()).toBe(false); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 531 | expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Syntax</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 532 | expect(menu.shownItem(2).active()).toBe(true); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 533 | expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 534 | |
| 535 | // Activate next (5) - ROLL |
| 536 | menu.next(); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 537 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 538 | expect(menu.shownItem(0).active()).toBe(true); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 539 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 540 | expect(menu.shownItem(1).active()).toBe(false); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 541 | expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 542 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 543 | expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 544 | |
| 545 | // Active next (6) |
| 546 | menu.next(); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 547 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 548 | expect(menu.shownItem(0).active()).toBe(false); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 549 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 550 | expect(menu.shownItem(1).active()).toBe(true); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 551 | expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 552 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 553 | expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 554 | }); |
| 555 | |
| 556 | it('should be nextable without active field', function () { |
| 557 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 558 | menu.limit(3); |
| 559 | expect(menu.show()).toBe(true); |
| 560 | menu.next(); |
| 561 | expect(menu.shownItem(0).active()).toEqual(true); |
| 562 | }); |
| 563 | |
| 564 | |
| 565 | it('should be prevable', function () { |
| 566 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 567 | menu._firstActive = true; |
| 568 | menu.limit(3); |
| 569 | expect(menu.show()).toBe(true); |
| 570 | |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 571 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 572 | expect(menu.shownItem(0).active()).toBe(true); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 573 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 574 | expect(menu.shownItem(1).active()).toBe(false); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 575 | expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 576 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 577 | expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 578 | |
| 579 | // Activate prev (1) - roll to bottom |
| 580 | menu.prev(); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 581 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 582 | expect(menu.shownItem(0).active()).toBe(false); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 583 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 584 | expect(menu.shownItem(1).active()).toBe(false); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 585 | expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Syntax</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 586 | expect(menu.shownItem(2).active()).toBe(true); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 587 | expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 588 | |
| 589 | // Activate prev (2) |
| 590 | menu.prev(); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 591 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 592 | expect(menu.shownItem(0).active()).toBe(false); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 593 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 594 | expect(menu.shownItem(1).active()).toBe(true); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 595 | expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Syntax</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 596 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 597 | expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 598 | |
| 599 | // Activate prev (3) |
| 600 | menu.prev(); |
| 601 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
| 602 | expect(menu.shownItem(0).active()).toBe(true); |
| 603 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
| 604 | expect(menu.shownItem(1).active()).toBe(false); |
| 605 | expect(menu.shownItem(2).name()).toEqual("Syntax"); |
| 606 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 607 | expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 608 | |
| 609 | // Activate prev (4) |
| 610 | menu.prev(); |
| 611 | expect(menu.shownItem(0).name()).toEqual("Lemma"); |
| 612 | expect(menu.shownItem(0).active()).toBe(true); |
| 613 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
| 614 | expect(menu.shownItem(1).active()).toBe(false); |
| 615 | expect(menu.shownItem(2).name()).toEqual("Part-of-Speech"); |
| 616 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 617 | expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 618 | |
| 619 | // Activate prev (5) |
| 620 | menu.prev(); |
| 621 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
| 622 | expect(menu.shownItem(0).active()).toBe(true); |
| 623 | expect(menu.shownItem(1).name()).toEqual("Lemma"); |
| 624 | expect(menu.shownItem(1).active()).toBe(false); |
| 625 | expect(menu.shownItem(2).name()).toEqual("Morphology"); |
| 626 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 627 | expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 628 | |
| 629 | // Activate next (1) |
| 630 | menu.next(); |
| 631 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
| 632 | expect(menu.shownItem(0).active()).toBe(false); |
| 633 | expect(menu.shownItem(1).name()).toEqual("Lemma"); |
| 634 | expect(menu.shownItem(1).active()).toBe(true); |
| 635 | expect(menu.shownItem(2).name()).toEqual("Morphology"); |
| 636 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 637 | expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 638 | |
| 639 | // Activate prev (6) |
| 640 | menu.prev(); |
| 641 | |
| 642 | // Activate prev (7) |
| 643 | menu.prev(); |
| 644 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
| 645 | expect(menu.shownItem(0).active()).toBe(false); |
| 646 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
| 647 | expect(menu.shownItem(1).active()).toBe(false); |
| 648 | expect(menu.shownItem(2).name()).toEqual("Syntax"); |
| 649 | expect(menu.shownItem(2).active()).toBe(true); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 650 | expect(menu.directElementChildrenByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 651 | }); |
| 652 | |
| 653 | it('should be prevable without active field', function () { |
| 654 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 655 | menu.limit(3); |
| 656 | expect(menu.show()).toBe(true); |
| 657 | menu.prev(); |
| 658 | expect(menu.shownItem(2).active()).toEqual(true); |
| 659 | expect(menu.shownItem(2).lcField()).toEqual(' syntax'); |
| 660 | }); |
| 661 | |
| 662 | it('should be navigatable and filterable (prefix = "o")', function () { |
| 663 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 664 | menu._firstActive = true; |
| 665 | menu.limit(2); |
| 666 | |
| 667 | expect(menu.prefix("o").show()).toBe(true); |
| 668 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 669 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 670 | expect(menu.shownItem(0).active()).toBe(true); |
| 671 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 672 | 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>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 673 | expect(menu.shownItem(1).active()).toBe(false); |
| 674 | expect(menu.shownItem(2)).toBe(undefined); |
| 675 | |
| 676 | // Next (1) |
| 677 | menu.next(); |
| 678 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 679 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 680 | expect(menu.shownItem(0).active()).toBe(false); |
| 681 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 682 | 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>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 683 | expect(menu.shownItem(1).active()).toBe(true); |
| 684 | expect(menu.shownItem(2)).toBe(undefined); |
| 685 | |
| 686 | // Next (2) |
| 687 | menu.next(); |
| 688 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 689 | 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>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 690 | expect(menu.shownItem(0).active()).toBe(false); |
| 691 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 692 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 693 | expect(menu.shownItem(1).active()).toBe(true); |
| 694 | expect(menu.shownItem(2)).toBe(undefined); |
| 695 | |
| 696 | // Next (3) - to prefix |
| 697 | menu.next(); |
| 698 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 699 | 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>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 700 | expect(menu.shownItem(0).active()).toBe(false); |
| 701 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 702 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 703 | expect(menu.shownItem(1).active()).toBe(false); |
| 704 | expect(menu.shownItem(2)).toBe(undefined); |
| 705 | |
| 706 | menu.next(); |
| 707 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 708 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 709 | expect(menu.shownItem(0).active()).toBe(true); |
| 710 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 711 | 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>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 712 | expect(menu.shownItem(1).active()).toBe(false); |
| 713 | expect(menu.shownItem(2)).toBe(undefined); |
| 714 | }); |
| 715 | |
| 716 | |
| 717 | it('should be navigatable and filterable (prefix = "ex", "e")', function () { |
| 718 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 719 | menu._firstActive = true; |
| 720 | |
| 721 | menu.limit(2); |
| 722 | expect(menu.prefix("ex").show()).toBe(true); |
| 723 | |
| 724 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 725 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 726 | expect(menu.shownItem(0).active()).toBe(true); |
| 727 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 728 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 729 | expect(menu.shownItem(1).active()).toBe(false); |
| 730 | expect(menu.shownItem(2)).toBe(undefined); |
| 731 | |
| 732 | // Next (1) |
| 733 | menu.next(); |
| 734 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 735 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 736 | expect(menu.shownItem(0).active()).toBe(false); |
| 737 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 738 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 739 | expect(menu.shownItem(1).active()).toBe(true); |
| 740 | expect(menu.shownItem(2)).toBe(undefined); |
| 741 | |
| 742 | // Next (2) |
| 743 | menu.next(); |
| 744 | |
| 745 | expect(menu.prefix()).toEqual('ex'); |
| 746 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 747 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 748 | expect(menu.shownItem(0).active()).toBe(false); |
| 749 | |
| 750 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 751 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 752 | expect(menu.shownItem(1).active()).toBe(false); |
| 753 | expect(menu.shownItem(2)).toBe(undefined); |
| 754 | |
| 755 | // Reset limit |
| 756 | menu.limit(5); |
| 757 | |
| 758 | // Change show |
| 759 | expect(menu.prefix("e").show()).toBe(true); |
| 760 | expect(menu._prefix.active()).toBe(false); |
| 761 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 762 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 763 | expect(menu.shownItem(0).active()).toBe(true); |
| 764 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 765 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 766 | expect(menu.shownItem(1).active()).toBe(false); |
| 767 | expect(menu.shownItem(2)).toBe(undefined); |
| 768 | |
| 769 | // Next (1) |
| 770 | menu.next(); |
| 771 | expect(menu._prefix.active()).toBe(false); |
| 772 | expect(menu.prefix()).toEqual('e'); |
| 773 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 774 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 775 | expect(menu.shownItem(0).active()).toBe(false); |
| 776 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 777 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 778 | expect(menu.shownItem(1).active()).toBe(true); |
| 779 | expect(menu.shownItem(2)).toBe(undefined); |
| 780 | |
| 781 | // Next (2) |
| 782 | menu.next(); |
| 783 | expect(menu._prefix.active()).toBe(true); |
| 784 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 785 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 786 | expect(menu.shownItem(0).active()).toBe(false); |
| 787 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 788 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 789 | expect(menu.shownItem(1).active()).toBe(false); |
| 790 | expect(menu.shownItem(2)).toBe(undefined); |
| 791 | |
| 792 | // Next (3) |
| 793 | menu.next(); |
| 794 | expect(menu._prefix.active()).toBe(false); |
| 795 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 796 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 797 | expect(menu.shownItem(0).active()).toBe(true); |
| 798 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 799 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 800 | expect(menu.shownItem(1).active()).toBe(false); |
| 801 | expect(menu.shownItem(2)).toBe(undefined); |
| 802 | }); |
| 803 | |
Akron | acffc65 | 2017-12-18 21:21:25 +0100 | [diff] [blame] | 804 | it('should be filterable (multiple prefix = "pro sin")', function () { |
| 805 | var menu = KorAP.HintMenu.create("drukola/p=", listMultiPrefix); |
| 806 | menu._firstActive = true; |
| 807 | |
| 808 | menu.limit(2); |
| 809 | expect(menu.prefix("pro sin").show()).toBe(true); |
| 810 | expect(menu.shownItem(0).name()).toEqual("PPS"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 811 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual( |
Akron | acffc65 | 2017-12-18 21:21:25 +0100 | [diff] [blame] | 812 | "<strong>PPS</strong><span>Personal <mark>Pro</mark>noun, <mark>Sin</mark>gular</span>" |
| 813 | ); |
| 814 | |
| 815 | expect(menu.shownItem(0).active()).toBe(true); |
| 816 | expect(menu.shownItem(1).name()).toEqual("PPSA"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 817 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>PPSA</strong><span>Personal <mark>Pro</mark>noun, <mark>Sin</mark>gular, Accusative</span>"); |
Akron | acffc65 | 2017-12-18 21:21:25 +0100 | [diff] [blame] | 818 | expect(menu.shownItem(1).active()).toBe(false); |
| 819 | |
| 820 | expect(menu.shownItem(2)).toBe(undefined); |
| 821 | }); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 822 | |
Akron | 359c7e1 | 2017-12-19 12:06:55 +0100 | [diff] [blame] | 823 | it('should be filterable (trimming = " p")', function () { |
| 824 | var menu = KorAP.HintMenu.create("/p=", listMultiPrefix); |
| 825 | // menu._firstActive = true; |
| 826 | |
| 827 | menu.limit(2); |
| 828 | expect(menu.show()).toBe(true); |
| 829 | menu._prefix.add(" "); |
| 830 | expect(menu.show()).toBe(true); |
| 831 | menu._prefix.add("p") |
| 832 | expect(menu.show()).toBe(true); |
| 833 | expect(menu.shownItem(0).name()).toEqual("PP"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 834 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual( |
Akron | 359c7e1 | 2017-12-19 12:06:55 +0100 | [diff] [blame] | 835 | "<strong><mark>P</mark><mark>P</mark></strong>"+ |
| 836 | "<span><mark>P</mark>ersonal <mark>P</mark>ronoun</span>" |
| 837 | ); |
| 838 | }); |
| 839 | |
| 840 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 841 | it('should choose prefix with failing prefix (1)', function () { |
| 842 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 843 | menu.limit(2); |
| 844 | expect(menu.prefix("exit").show()).toBe(true); |
| 845 | expect(menu.element().querySelector('li')).toBe(null); |
| 846 | expect(menu.shownItem(0)).toBeUndefined(); |
| 847 | expect(menu._prefix.active()).toBe(true); |
| 848 | }); |
| 849 | |
| 850 | |
| 851 | it('should choose prefix with failing prefix (2)', function () { |
| 852 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 853 | menu.limit(2); |
| 854 | expect(menu.show()).toBe(true); |
| 855 | expect(menu.prefix("exit").show()).toBe(true); |
| 856 | expect(menu.element().querySelector('li')).toBe(null); |
| 857 | expect(menu.shownItem(0)).toBeUndefined(); |
| 858 | expect(menu._prefix.active()).toBe(true); |
| 859 | }); |
| 860 | |
| 861 | it('should ignore navigation with failing prefix', function () { |
| 862 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 863 | menu.limit(2); |
| 864 | expect(menu.show()).toBe(true); |
| 865 | |
| 866 | menu.next(); |
| 867 | |
| 868 | expect(menu.prefix("exit").show()).toBe(true); |
| 869 | expect(menu.element().querySelector('li')).toBe(null); |
| 870 | expect(menu.shownItem(0)).toBeUndefined(); |
| 871 | expect(menu._prefix.active()).toBe(true); |
| 872 | |
| 873 | menu.next(); |
| 874 | expect(menu._prefix.active()).toBe(true); |
| 875 | |
| 876 | menu.prev(); |
| 877 | expect(menu._prefix.active()).toBe(true); |
| 878 | |
| 879 | }); |
| 880 | |
| 881 | it('should be navigatable with prefix', function () { |
| 882 | var menu = KorAP.HintMenu.create("cnx/", demolist); |
| 883 | menu._firstActive = true; |
| 884 | |
| 885 | menu.limit(3); |
| 886 | |
| 887 | expect(menu.show()).toBe(true); |
| 888 | expect(menu.prefix()).toEqual(""); |
| 889 | |
| 890 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 891 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 892 | expect(menu.shownItem(0).active()).toBe(true); |
| 893 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 894 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 895 | expect(menu.shownItem(1).active()).toBe(false); |
| 896 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 897 | expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 898 | expect(menu.shownItem(2).active()).toBe(false); |
| 899 | expect(menu.shownItem(3)).toBe(undefined); |
| 900 | |
| 901 | menu._prefix.add('a'); |
| 902 | expect(menu.show()).toBe(true); |
| 903 | expect(menu.prefix()).toEqual("a"); |
| 904 | expect(menu.shownItem(0).name()).toEqual("Autor"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 905 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 906 | |
| 907 | menu._prefix.add('u'); |
| 908 | expect(menu.show()).toBe(true); |
| 909 | expect(menu.prefix()).toEqual("au"); |
| 910 | expect(menu.shownItem(0).name()).toEqual("Autor"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 911 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong><mark>Au</mark>tor</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 912 | |
| 913 | menu._prefix.chop(); |
| 914 | expect(menu.show()).toBe(true); |
| 915 | expect(menu.prefix()).toEqual("a"); |
| 916 | expect(menu.shownItem(0).name()).toEqual("Autor"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 917 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 918 | |
| 919 | menu._prefix.chop(); |
| 920 | expect(menu.show()).toBe(true); |
| 921 | expect(menu.prefix()).toEqual(""); |
| 922 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 923 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 924 | expect(menu.shownItem(0).active()).toBe(true); |
| 925 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 926 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 927 | expect(menu.shownItem(1).active()).toBe(false); |
| 928 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 929 | expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 930 | expect(menu.shownItem(2).active()).toBe(false); |
| 931 | expect(menu.shownItem(3)).toBe(undefined); |
| 932 | |
| 933 | // Forward |
| 934 | menu._prefix.chop(); |
| 935 | expect(menu.show()).toBe(true); |
| 936 | expect(menu.prefix()).toEqual(""); |
| 937 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 938 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 939 | expect(menu.shownItem(0).active()).toBe(true); |
| 940 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 941 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 942 | expect(menu.shownItem(1).active()).toBe(false); |
| 943 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 944 | expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 945 | expect(menu.shownItem(2).active()).toBe(false); |
| 946 | |
| 947 | // Forward |
| 948 | menu.next(); |
| 949 | expect(menu.prefix()).toEqual(""); |
| 950 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 951 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 952 | expect(menu.shownItem(0).active()).toBe(false); |
| 953 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 954 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 955 | expect(menu.shownItem(1).active()).toBe(true); |
| 956 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 957 | expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 958 | expect(menu.shownItem(2).active()).toBe(false); |
| 959 | expect(menu.shownItem(3)).toBe(undefined); |
| 960 | |
| 961 | // Forward |
| 962 | menu.next(); |
| 963 | expect(menu.prefix()).toEqual(""); |
| 964 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 965 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 966 | expect(menu.shownItem(0).active()).toBe(false); |
| 967 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 968 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 969 | expect(menu.shownItem(1).active()).toBe(false); |
| 970 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 971 | expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 972 | expect(menu.shownItem(2).active()).toBe(true); |
| 973 | expect(menu.shownItem(3)).toBe(undefined); |
| 974 | |
| 975 | // Forward |
| 976 | menu.next(); |
| 977 | expect(menu.prefix()).toEqual(""); |
| 978 | expect(menu.shownItem(0).name()).toEqual("Untertitel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 979 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 980 | expect(menu.shownItem(0).active()).toBe(false); |
| 981 | expect(menu.shownItem(1).name()).toEqual("Veröffentlichungsdatum"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 982 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 983 | expect(menu.shownItem(1).active()).toBe(false); |
| 984 | expect(menu.shownItem(2).name()).toEqual("Länge"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 985 | expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Länge</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 986 | expect(menu.shownItem(2).active()).toBe(true); |
| 987 | expect(menu.shownItem(3)).toBe(undefined); |
| 988 | |
| 989 | // Forward |
| 990 | menu.next(); |
| 991 | expect(menu.prefix()).toEqual(""); |
| 992 | expect(menu.shownItem(0).name()).toEqual("Veröffentlichungsdatum"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 993 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 994 | expect(menu.shownItem(0).active()).toBe(false); |
| 995 | expect(menu.shownItem(1).name()).toEqual("Länge"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 996 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Länge</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 997 | expect(menu.shownItem(1).active()).toBe(false); |
| 998 | expect(menu.shownItem(2).name()).toEqual("Autor"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 999 | expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Autor</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1000 | expect(menu.shownItem(2).active()).toBe(true); |
| 1001 | expect(menu.shownItem(3)).toBe(undefined); |
| 1002 | |
| 1003 | // Forward |
| 1004 | menu.next(); |
| 1005 | expect(menu.prefix()).toEqual(""); |
| 1006 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 1007 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1008 | expect(menu.shownItem(0).active()).toBe(true); |
| 1009 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 1010 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1011 | expect(menu.shownItem(1).active()).toBe(false); |
| 1012 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 1013 | expect(menu.directElementChildrenByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1014 | expect(menu.shownItem(2).active()).toBe(false); |
| 1015 | }); |
| 1016 | |
| 1017 | |
| 1018 | it('should be navigatable with a prefix (1)', function () { |
| 1019 | var menu = KorAP.HintMenu.create("cnx/", demolist); |
| 1020 | menu._firstActive = true; |
| 1021 | |
| 1022 | menu.limit(3); |
| 1023 | |
| 1024 | expect(menu.show()).toBe(true); |
| 1025 | expect(menu.prefix()).toEqual(""); |
| 1026 | |
| 1027 | // Add prefix in uppercase - but check in lowercase |
| 1028 | menu.prefix('El'); |
| 1029 | expect(menu.show()).toBe(true); |
| 1030 | |
| 1031 | expect(menu.prefix()).toEqual("El"); |
| 1032 | expect(menu._prefix.active()).toEqual(false); |
| 1033 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 1034 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1035 | expect(menu.shownItem(0).active()).toBe(true); |
| 1036 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 1037 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1038 | expect(menu.shownItem(1).active()).toBe(false); |
| 1039 | expect(menu.shownItem(2)).toBe(undefined); |
| 1040 | |
| 1041 | // Forward |
| 1042 | menu.next(); |
| 1043 | expect(menu.prefix()).toEqual("El"); |
| 1044 | expect(menu._prefix.active()).toEqual(false); |
| 1045 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 1046 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1047 | expect(menu.shownItem(0).active()).toBe(false); |
| 1048 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 1049 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1050 | expect(menu.shownItem(1).active()).toBe(true); |
| 1051 | expect(menu.shownItem(2)).toBe(undefined); |
| 1052 | |
| 1053 | // Forward |
| 1054 | menu.next(); |
| 1055 | expect(menu.prefix()).toEqual("El"); |
| 1056 | expect(menu._prefix.active()).toEqual(true); |
| 1057 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 1058 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1059 | expect(menu.shownItem(0).active()).toBe(false); |
| 1060 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 1061 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1062 | expect(menu.shownItem(1).active()).toBe(false); |
| 1063 | expect(menu.shownItem(2)).toBe(undefined); |
| 1064 | |
| 1065 | // Backward |
| 1066 | menu.prev(); |
| 1067 | expect(menu.prefix()).toEqual("El"); |
| 1068 | expect(menu._prefix.active()).toEqual(false); |
| 1069 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 1070 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1071 | expect(menu.shownItem(0).active()).toBe(false); |
| 1072 | |
| 1073 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 1074 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1075 | expect(menu.shownItem(1).active()).toBe(true); |
| 1076 | expect(menu.shownItem(2)).toBe(undefined); |
| 1077 | }); |
| 1078 | |
| 1079 | |
| 1080 | it('should be navigatable with a prefix (2)', function () { |
| 1081 | var menu = KorAP.HintMenu.create("cnx/", demolist); |
| 1082 | menu._firstActive = true; |
| 1083 | |
| 1084 | menu.limit(3); |
| 1085 | expect(menu.show()).toBe(true); |
| 1086 | expect(menu.prefix()).toEqual(""); |
| 1087 | menu.prefix('el'); |
| 1088 | expect(menu.show()).toBe(true); |
| 1089 | |
| 1090 | expect(menu.prefix()).toEqual("el"); |
| 1091 | expect(menu._prefix.active()).toEqual(false); |
| 1092 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 1093 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1094 | expect(menu.shownItem(0).active()).toBe(true); |
| 1095 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 1096 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1097 | expect(menu.shownItem(1).active()).toBe(false); |
| 1098 | expect(menu.shownItem(2)).toBe(undefined); |
| 1099 | |
| 1100 | // Backward |
| 1101 | menu.prev(); |
| 1102 | expect(menu._prefix.active()).toEqual(true); |
| 1103 | |
| 1104 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 1105 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1106 | expect(menu.shownItem(0).active()).toBe(false); |
| 1107 | |
| 1108 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 1109 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1110 | expect(menu.shownItem(1).active()).toBe(false); |
| 1111 | expect(menu.shownItem(2)).toBe(undefined); |
| 1112 | |
| 1113 | // Backward |
| 1114 | menu.prev(); |
| 1115 | expect(menu._prefix.active()).toEqual(false); |
| 1116 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 1117 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1118 | expect(menu.shownItem(0).active()).toBe(false); |
| 1119 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 1120 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1121 | expect(menu.shownItem(1).active()).toBe(true); |
| 1122 | expect(menu.shownItem(2)).toBe(undefined); |
| 1123 | }); |
| 1124 | |
| 1125 | it('should be navigatable with a prefix (3)', function () { |
| 1126 | var menu = KorAP.HintMenu.create("cnx/", demolist); |
| 1127 | menu._firstActive = true; |
| 1128 | menu.limit(3); |
| 1129 | expect(menu.show()).toBe(true); |
| 1130 | expect(menu.prefix()).toEqual(""); |
| 1131 | menu.prefix('el'); |
| 1132 | expect(menu.show()).toBe(true); |
| 1133 | |
| 1134 | expect(menu.prefix()).toEqual("el"); |
| 1135 | expect(menu._prefix.active()).toEqual(false); |
| 1136 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 1137 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1138 | expect(menu.shownItem(0).active()).toBe(true); |
| 1139 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 1140 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1141 | expect(menu.shownItem(1).active()).toBe(false); |
| 1142 | expect(menu.shownItem(2)).toBe(undefined); |
| 1143 | |
| 1144 | // Backward |
| 1145 | menu.prev(); |
| 1146 | expect(menu._prefix.active()).toEqual(true); |
| 1147 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 1148 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1149 | expect(menu.shownItem(0).active()).toBe(false); |
| 1150 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 1151 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1152 | expect(menu.shownItem(1).active()).toBe(false); |
| 1153 | expect(menu.shownItem(2)).toBe(undefined); |
| 1154 | |
| 1155 | |
| 1156 | // Forward |
| 1157 | menu.next(); |
| 1158 | expect(menu.prefix()).toEqual("el"); |
| 1159 | expect(menu._prefix.active()).toEqual(false); |
| 1160 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 1161 | expect(menu.directElementChildrenByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1162 | expect(menu.shownItem(0).active()).toBe(true); |
| 1163 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 7b0fbf9 | 2021-07-14 11:25:59 +0200 | [diff] [blame] | 1164 | expect(menu.directElementChildrenByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1165 | expect(menu.shownItem(1).active()).toBe(false); |
| 1166 | expect(menu.shownItem(2)).toBe(undefined); |
| 1167 | |
| 1168 | }); |
| 1169 | |
| 1170 | it('should show screens by offset', function () { |
| 1171 | var menu = KorAP.HintMenu.create('cnx/', demolist); |
| 1172 | menu.limit(3); |
| 1173 | expect(menu.show()).toBe(true); |
| 1174 | |
| 1175 | expect(menu.shownItem(0).active()).toBe(false); |
| 1176 | expect(menu.shownItem(1).active()).toBe(false); |
| 1177 | expect(menu.shownItem(2).active()).toBe(false); |
| 1178 | |
| 1179 | // Highlight the first entry |
| 1180 | menu.next(); |
| 1181 | |
| 1182 | expect(menu.shownItem(0).active()).toBe(true); |
| 1183 | expect(menu.shownItem(1).active()).toBe(false); |
| 1184 | expect(menu.shownItem(2).active()).toBe(false); |
| 1185 | |
| 1186 | // Highlight the second entry |
| 1187 | menu.next(); |
| 1188 | |
| 1189 | expect(menu.shownItem(0).active()).toBe(false); |
| 1190 | expect(menu.shownItem(1).active()).toBe(true); |
| 1191 | expect(menu.shownItem(2).active()).toBe(false); |
| 1192 | expect(menu.shownItem(3)).toBe(undefined); |
| 1193 | |
| 1194 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1195 | expect(menu.shownItem(1).lcField()).toEqual(' untertitel'); |
| 1196 | |
| 1197 | // Move to first screen |
| 1198 | menu.screen(0); |
| 1199 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1200 | expect(menu.shownItem(1).lcField()).toEqual(' untertitel'); |
| 1201 | expect(menu.shownItem(0).active()).toBe(false); |
| 1202 | expect(menu.shownItem(1).active()).toBe(true); |
| 1203 | expect(menu.shownItem(2).active()).toBe(false); |
| 1204 | expect(menu.shownItem(3)).toBe(undefined); |
| 1205 | |
| 1206 | // Move to second screen |
| 1207 | menu.screen(1); |
| 1208 | expect(menu.shownItem(0).lcField()).toEqual(' untertitel'); |
| 1209 | expect(menu.shownItem(0).active()).toBe(true); |
| 1210 | expect(menu.shownItem(1).active()).toBe(false); |
| 1211 | expect(menu.shownItem(2).active()).toBe(false); |
| 1212 | expect(menu.shownItem(3)).toBe(undefined); |
| 1213 | |
| 1214 | menu.screen(2); |
| 1215 | expect(menu.shownItem(0).lcField()).toEqual(' veröffentlichungsdatum'); |
| 1216 | expect(menu.shownItem(0).active()).toBe(false); |
| 1217 | expect(menu.shownItem(1).active()).toBe(false); |
| 1218 | expect(menu.shownItem(2).active()).toBe(false); |
| 1219 | expect(menu.shownItem(3)).toBe(undefined); |
| 1220 | |
| 1221 | menu.screen(1); |
| 1222 | expect(menu.shownItem(0).lcField()).toEqual(' untertitel'); |
| 1223 | expect(menu.shownItem(0).active()).toBe(true); |
| 1224 | expect(menu.shownItem(1).active()).toBe(false); |
| 1225 | expect(menu.shownItem(2).active()).toBe(false); |
| 1226 | expect(menu.shownItem(3)).toBe(undefined); |
| 1227 | }); |
| 1228 | |
| 1229 | it('should show screens by offset when prefixed', function () { |
| 1230 | var menu = KorAP.HintMenu.create('cnx/', demolist); |
| 1231 | menu.limit(3); |
| 1232 | expect(menu.prefix("e").show()).toBe(true); |
| 1233 | expect(menu.shownItem(0).active()).toBe(false); |
| 1234 | expect(menu.shownItem(1).active()).toBe(false); |
| 1235 | expect(menu.shownItem(2).active()).toBe(false); |
| 1236 | |
| 1237 | expect(menu.shownItem(0).element().innerHTML).toEqual('<strong>Tit<mark>e</mark>l</strong>'); |
| 1238 | menu.screen(1); |
| 1239 | expect(menu.shownItem(0).element().innerHTML).toEqual('<strong>Unt<mark>e</mark>rtit<mark>e</mark>l</strong>'); |
| 1240 | }); |
| 1241 | |
| 1242 | |
| 1243 | it('should be page downable', function () { |
| 1244 | var menu = KorAP.OwnMenu.create(demolonglist); |
| 1245 | menu.limit(3); |
| 1246 | |
| 1247 | expect(menu.show(0)).toBe(true); |
| 1248 | |
| 1249 | expect(menu.shownItem(0).active()).toBe(true); |
| 1250 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1251 | expect(menu.shownItem(1).active()).toBe(false); |
| 1252 | expect(menu.shownItem(2).active()).toBe(false); |
| 1253 | expect(menu.shownItem(3)).toBe(undefined); |
| 1254 | |
| 1255 | menu.pageDown(); |
| 1256 | |
| 1257 | expect(menu.shownItem(0).lcField()).toEqual(' länge'); |
| 1258 | expect(menu.shownItem(0).active()).toBe(false); |
| 1259 | expect(menu.shownItem(1).active()).toBe(false); |
| 1260 | expect(menu.shownItem(2).active()).toBe(false); |
| 1261 | |
| 1262 | menu.pageDown(); |
| 1263 | |
| 1264 | expect(menu.shownItem(0).lcField()).toEqual(' corpusid'); |
| 1265 | expect(menu.shownItem(0).active()).toBe(false); |
| 1266 | expect(menu.shownItem(1).active()).toBe(false); |
| 1267 | expect(menu.shownItem(2).active()).toBe(false); |
| 1268 | |
| 1269 | // Doesn't matter |
| 1270 | menu.pageDown(); |
| 1271 | |
| 1272 | expect(menu.shownItem(0).lcField()).toEqual(' corpusid'); |
| 1273 | expect(menu.shownItem(0).active()).toBe(false); |
| 1274 | expect(menu.shownItem(1).active()).toBe(false); |
| 1275 | expect(menu.shownItem(2).active()).toBe(false); |
| 1276 | }); |
| 1277 | |
| 1278 | it('should be page downable with prefix', function () { |
| 1279 | var menu = KorAP.OwnMenu.create(demolonglist); |
| 1280 | menu.limit(3); |
| 1281 | |
| 1282 | expect(menu.prefix('e').show(0)).toBe(true); |
| 1283 | |
| 1284 | expect(menu.shownItem(0).active()).toBe(true); |
| 1285 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1286 | expect(menu.shownItem(1).active()).toBe(false); |
| 1287 | expect(menu.shownItem(1).lcField()).toEqual(' untertitel'); |
| 1288 | expect(menu.shownItem(2).active()).toBe(false); |
| 1289 | expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum'); |
| 1290 | expect(menu.shownItem(3)).toBe(undefined); |
| 1291 | |
| 1292 | menu.pageDown(); |
| 1293 | |
| 1294 | expect(menu.shownItem(0).active()).toBe(false); |
| 1295 | expect(menu.shownItem(0).lcField()).toEqual(' länge'); |
| 1296 | expect(menu.shownItem(1).active()).toBe(false); |
| 1297 | expect(menu.shownItem(1).lcField()).toEqual(' genre'); |
| 1298 | expect(menu.shownItem(2).active()).toBe(false); |
| 1299 | expect(menu.shownItem(2).lcField()).toEqual(' textid'); |
| 1300 | |
| 1301 | // Doesn't matter |
| 1302 | menu.pageDown(); |
| 1303 | |
| 1304 | expect(menu.shownItem(0).active()).toBe(false); |
| 1305 | expect(menu.shownItem(0).lcField()).toEqual(' länge'); |
| 1306 | expect(menu.shownItem(1).active()).toBe(false); |
| 1307 | expect(menu.shownItem(1).lcField()).toEqual(' genre'); |
| 1308 | expect(menu.shownItem(2).active()).toBe(false); |
| 1309 | expect(menu.shownItem(2).lcField()).toEqual(' textid'); |
| 1310 | }); |
| 1311 | |
| 1312 | |
| 1313 | it('should be page upable', function () { |
| 1314 | var menu = KorAP.OwnMenu.create(demolonglist); |
| 1315 | menu.limit(3); |
| 1316 | |
| 1317 | // Choose the final value |
| 1318 | expect(menu.show(1000)).toBe(true); |
| 1319 | |
| 1320 | expect(menu.shownItem(0).active()).toBe(false); |
| 1321 | expect(menu.shownItem(1).active()).toBe(false); |
| 1322 | expect(menu.shownItem(2).active()).toBe(true); |
| 1323 | expect(menu.shownItem(2).lcField()).toEqual(' textid'); |
| 1324 | expect(menu.shownItem(3)).toBe(undefined); |
| 1325 | |
| 1326 | menu.pageUp(); |
| 1327 | |
| 1328 | expect(menu.shownItem(0).lcField()).toEqual(' länge'); |
| 1329 | expect(menu.shownItem(0).active()).toBe(false); |
| 1330 | expect(menu.shownItem(1).active()).toBe(false); |
| 1331 | expect(menu.shownItem(2).active()).toBe(false); |
| 1332 | |
| 1333 | menu.pageUp(); |
| 1334 | |
| 1335 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1336 | expect(menu.shownItem(0).active()).toBe(false); |
| 1337 | expect(menu.shownItem(1).active()).toBe(false); |
| 1338 | expect(menu.shownItem(2).active()).toBe(false); |
| 1339 | |
| 1340 | // Doesn't matter |
| 1341 | menu.pageUp(); |
| 1342 | |
| 1343 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1344 | expect(menu.shownItem(0).active()).toBe(false); |
| 1345 | expect(menu.shownItem(1).active()).toBe(false); |
| 1346 | expect(menu.shownItem(2).active()).toBe(false); |
| 1347 | }); |
| 1348 | |
| 1349 | it('should be page upable with prefix', function () { |
| 1350 | var menu = KorAP.OwnMenu.create(demolonglist); |
| 1351 | menu.limit(3); |
| 1352 | |
| 1353 | // Choose the final value |
| 1354 | expect(menu.prefix("e").show(1000)).toBe(true); |
| 1355 | |
| 1356 | expect(menu.shownItem(0).active()).toBe(false); |
| 1357 | expect(menu.shownItem(0).lcField()).toEqual(' länge'); |
| 1358 | expect(menu.shownItem(1).active()).toBe(false); |
| 1359 | expect(menu.shownItem(1).lcField()).toEqual(' genre'); |
| 1360 | expect(menu.shownItem(2).active()).toBe(true); |
| 1361 | expect(menu.shownItem(2).lcField()).toEqual(' textid'); |
| 1362 | expect(menu.shownItem(3)).toBe(undefined); |
| 1363 | |
| 1364 | menu.pageUp(); |
| 1365 | |
| 1366 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1367 | expect(menu.shownItem(0).active()).toBe(false); |
| 1368 | expect(menu.shownItem(1).active()).toBe(false); |
| 1369 | expect(menu.shownItem(1).lcField()).toEqual(' untertitel'); |
| 1370 | expect(menu.shownItem(2).active()).toBe(false); |
| 1371 | expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum'); |
| 1372 | |
| 1373 | // Doesn't matter |
| 1374 | menu.pageUp(); |
| 1375 | |
| 1376 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1377 | expect(menu.shownItem(0).active()).toBe(false); |
| 1378 | expect(menu.shownItem(1).active()).toBe(false); |
| 1379 | expect(menu.shownItem(1).lcField()).toEqual(' untertitel'); |
| 1380 | expect(menu.shownItem(2).active()).toBe(false); |
| 1381 | expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum'); |
| 1382 | }); |
| 1383 | |
Akron | e817b88 | 2018-08-31 14:09:17 +0200 | [diff] [blame] | 1384 | it('should be view upable and downable (1)', function () { |
| 1385 | var menu = KorAP.OwnMenu.create(demolonglist); |
| 1386 | menu.limit(7); |
| 1387 | |
| 1388 | // Choose the final value |
| 1389 | expect(menu.show(1)).toBe(true); |
| 1390 | |
| 1391 | expect(menu.shownItem(0).active()).toBe(false); |
| 1392 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1393 | expect(menu.shownItem(1).active()).toBe(true); |
| 1394 | expect(menu.shownItem(2).active()).toBe(false); |
| 1395 | expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum'); |
| 1396 | expect(menu.shownItem(6).active()).toBe(false); |
| 1397 | expect(menu.shownItem(7)).toBe(undefined); |
| 1398 | |
| 1399 | // Doesn't change anything |
| 1400 | menu.viewUp(); |
| 1401 | |
| 1402 | expect(menu.shownItem(0).active()).toBe(false); |
| 1403 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1404 | expect(menu.shownItem(1).active()).toBe(true); |
| 1405 | |
| 1406 | menu.viewDown(); |
| 1407 | |
| 1408 | expect(menu.shownItem(0).active()).toBe(true); |
| 1409 | expect(menu.shownItem(0).lcField()).toEqual(' untertitel'); |
| 1410 | expect(menu.shownItem(1).active()).toBe(false); |
| 1411 | |
| 1412 | menu.viewDown(); |
| 1413 | |
| 1414 | expect(menu.shownItem(0).active()).toBe(false); |
| 1415 | expect(menu.shownItem(0).lcField()).toEqual(' veröffentlichungsdatum'); |
| 1416 | expect(menu.shownItem(1).active()).toBe(false); |
| 1417 | |
| 1418 | // No effect anymore |
| 1419 | menu.viewDown(); |
| 1420 | |
| 1421 | expect(menu.shownItem(0).active()).toBe(false); |
| 1422 | expect(menu.shownItem(0).lcField()).toEqual(' veröffentlichungsdatum'); |
| 1423 | expect(menu.shownItem(1).active()).toBe(false); |
| 1424 | }); |
| 1425 | |
| 1426 | it('should be view upable and downable (2)', function () { |
| 1427 | |
| 1428 | // List is longer than limit |
| 1429 | var menu = KorAP.OwnMenu.create(demolist); |
| 1430 | menu.limit(7); |
| 1431 | |
| 1432 | // Choose the final value |
| 1433 | expect(menu.show(1)).toBe(true); |
| 1434 | |
| 1435 | expect(menu.shownItem(0).active()).toBe(false); |
| 1436 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1437 | expect(menu.shownItem(1).active()).toBe(true); |
| 1438 | expect(menu.shownItem(2).active()).toBe(false); |
| 1439 | expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum'); |
| 1440 | expect(menu.shownItem(4).active()).toBe(false); |
| 1441 | expect(menu.shownItem(5)).toBe(undefined); |
| 1442 | |
| 1443 | // Doesn't change anything |
| 1444 | menu.viewUp(); |
| 1445 | |
| 1446 | expect(menu.shownItem(0).active()).toBe(false); |
| 1447 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1448 | expect(menu.shownItem(1).active()).toBe(true); |
| 1449 | |
| 1450 | menu.viewDown(); |
| 1451 | |
| 1452 | expect(menu.shownItem(0).active()).toBe(false); |
| 1453 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1454 | expect(menu.shownItem(1).active()).toBe(true); |
| 1455 | }); |
| 1456 | |
| 1457 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1458 | it('should scroll to a chosen value (1)', function () { |
| 1459 | var menu = KorAP.OwnMenu.create(demolist); |
| 1460 | menu.limit(3); |
| 1461 | |
| 1462 | // Choose value 1 |
| 1463 | expect(menu.show(1)).toBe(true); |
| 1464 | |
| 1465 | expect(menu.shownItem(0).active()).toBe(false); |
| 1466 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1467 | expect(menu.shownItem(1).active()).toBe(true); |
| 1468 | expect(menu.shownItem(2).active()).toBe(false); |
| 1469 | expect(menu.shownItem(3)).toBe(undefined); |
| 1470 | |
| 1471 | // Choose value 2 |
| 1472 | expect(menu.show(2)).toBe(true); |
| 1473 | |
| 1474 | expect(menu.shownItem(0).active()).toBe(false); |
| 1475 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1476 | expect(menu.shownItem(1).active()).toBe(false); |
| 1477 | expect(menu.shownItem(2).active()).toBe(true); |
| 1478 | expect(menu.shownItem(3)).toBe(undefined); |
| 1479 | }); |
| 1480 | |
| 1481 | it('should scroll to a chosen value (2)', function () { |
| 1482 | var menu = KorAP.OwnMenu.create(demolonglist); |
| 1483 | |
| 1484 | // Choose value 3 |
| 1485 | expect(menu.limit(3).show(3)).toBe(true); |
| 1486 | expect(menu.shownItem(0).lcField()).toEqual(' länge'); |
| 1487 | expect(menu.shownItem(0).active()).toBe(true); |
| 1488 | expect(menu.shownItem(1).active()).toBe(false); |
| 1489 | expect(menu.shownItem(2).active()).toBe(false); |
| 1490 | expect(menu.shownItem(3)).toBe(undefined); |
| 1491 | }); |
| 1492 | |
| 1493 | xit('should scroll to a chosen value after prefixing, if the chosen value is live'); |
Akron | 8aa1c52 | 2021-07-23 11:33:49 +0200 | [diff] [blame] | 1494 | |
| 1495 | it('should be expendable', function () { |
| 1496 | var menu = menuClass.create([]); |
| 1497 | let entryData = 'empty'; |
| 1498 | menu.readItems([ |
| 1499 | ['a', '', function () { entryData = 'a' }], |
| 1500 | ['bb', '', function () { entryData = 'bb' }], |
| 1501 | ['ccc', '', function () { entryData = 'ccc' }], |
| 1502 | ]); |
| 1503 | |
| 1504 | expect(menu.limit(3).show(3)).toBe(true); |
| 1505 | expect(menu.shownItem(0).lcField()).toEqual(' a'); |
| 1506 | expect(menu.shownItem(1).lcField()).toEqual(' bb'); |
| 1507 | expect(menu.shownItem(2).lcField()).toEqual(' ccc'); |
| 1508 | expect(entryData).toEqual('empty'); |
| 1509 | menu.shownItem(1).element().click(); |
| 1510 | expect(entryData).toEqual('bb'); |
| 1511 | expect(menu.lengthField().element().innerText).toEqual("a--bb--ccc--") |
| 1512 | expect(menu.slider().length()).toEqual(3); |
| 1513 | |
| 1514 | let obj = menu.itemClass().create( |
| 1515 | ['dddd','',function () { entryData = 'dddd'} ] |
| 1516 | ); |
| 1517 | menu.append(obj) |
| 1518 | |
| 1519 | expect(menu.limit(2).show(1)).toBe(true); |
| 1520 | expect(menu.shownItem(0).lcField()).toEqual(' a'); |
| 1521 | expect(menu.shownItem(1).lcField()).toEqual(' bb'); |
| 1522 | menu.next(); |
| 1523 | expect(menu.shownItem(1).lcField()).toEqual(' ccc'); |
| 1524 | menu.next(); |
| 1525 | expect(menu.shownItem(1).lcField()).toEqual(' dddd'); |
| 1526 | menu.next(); |
| 1527 | expect(menu.shownItem(0).lcField()).toEqual(' a'); |
| 1528 | expect(menu.lengthField().element().innerText).toEqual("a--bb--ccc--dddd--") |
| 1529 | expect(menu.slider().length()).toEqual(4); |
| 1530 | }); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1531 | }); |
| 1532 | |
| 1533 | describe('KorAP.Prefix', function () { |
| 1534 | it('should be initializable', function () { |
| 1535 | var p = prefixClass.create(); |
| 1536 | expect(p.element().classList.contains('pref')).toBeTruthy(); |
Akron | f21bf74 | 2021-05-19 13:30:38 +0200 | [diff] [blame] | 1537 | expect(p.element().classList.contains('non-item')).toBeTruthy(); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1538 | expect(p.isSet()).not.toBeTruthy(); |
| 1539 | |
| 1540 | /* |
| 1541 | expect(mi.lcField()).toEqual(' baum'); |
| 1542 | */ |
| 1543 | |
| 1544 | }); |
| 1545 | |
| 1546 | it('should be modifiable', function () { |
| 1547 | var p = prefixClass.create(); |
| 1548 | expect(p.value()).toEqual(''); |
| 1549 | expect(p.element().firstChild).toBeNull(); |
| 1550 | |
| 1551 | // Set string |
| 1552 | expect(p.value('Test')).toEqual('Test'); |
| 1553 | expect(p.value()).toEqual('Test'); |
| 1554 | expect(p.element().firstChild.nodeValue).toEqual('Test'); |
| 1555 | |
| 1556 | // Add string |
| 1557 | expect(p.add('ified')).toEqual('Testified'); |
| 1558 | expect(p.value()).toEqual('Testified'); |
| 1559 | expect(p.element().firstChild.nodeValue).toEqual('Testified'); |
| 1560 | |
| 1561 | // Clear string |
| 1562 | p.clear(); |
| 1563 | expect(p.value()).toEqual(''); |
| 1564 | expect(p.element().firstChild).toBeNull(); |
| 1565 | |
| 1566 | // Set string |
| 1567 | expect(p.value('Test')).toEqual('Test'); |
| 1568 | expect(p.value()).toEqual('Test'); |
| 1569 | expect(p.element().firstChild.nodeValue).toEqual('Test'); |
| 1570 | |
| 1571 | expect(p.chop()).toEqual('Tes'); |
| 1572 | expect(p.value()).toEqual('Tes'); |
| 1573 | expect(p.element().firstChild.nodeValue).toEqual('Tes'); |
| 1574 | |
| 1575 | expect(p.chop()).toEqual('Te'); |
| 1576 | expect(p.value()).toEqual('Te'); |
| 1577 | expect(p.element().firstChild.nodeValue).toEqual('Te'); |
| 1578 | |
| 1579 | expect(p.chop()).toEqual('T'); |
| 1580 | expect(p.value()).toEqual('T'); |
| 1581 | expect(p.element().firstChild.nodeValue).toEqual('T'); |
| 1582 | |
| 1583 | expect(p.chop()).toEqual(''); |
| 1584 | expect(p.value()).toEqual(''); |
| 1585 | expect(p.element().firstChild).toBeNull(); |
| 1586 | }); |
| 1587 | |
| 1588 | it('should be activatable', function () { |
| 1589 | var p = prefixClass.create(); |
| 1590 | expect(p.value()).toEqual(''); |
| 1591 | expect(p.element().firstChild).toBeNull(); |
| 1592 | |
| 1593 | expect(p.value('Test')).toEqual('Test'); |
| 1594 | expect(p.element().firstChild.nodeValue).toEqual('Test'); |
| 1595 | |
| 1596 | expect(p.active()).not.toBeTruthy(); |
| 1597 | expect(p.element().classList.contains('active')).not.toBeTruthy(); |
| 1598 | |
| 1599 | p.active(true); |
| 1600 | expect(p.active()).toBeTruthy(); |
| 1601 | expect(p.element().classList.contains('active')).toBeTruthy(); |
| 1602 | }); |
| 1603 | }); |
| 1604 | |
| 1605 | describe('KorAP.LengthField', function () { |
| 1606 | it('should be initializable', function () { |
| 1607 | var l = lengthFieldClass.create(); |
| 1608 | expect(l.element().classList.contains('lengthField')).toBeTruthy(); |
| 1609 | expect(l.element().children.length).toEqual(0); |
| 1610 | }); |
| 1611 | |
| 1612 | it('should be extensible', function () { |
| 1613 | var l = lengthFieldClass.create(); |
| 1614 | l.add(['Baum']); |
| 1615 | expect(l.element().children.length).toEqual(1); |
| 1616 | expect(l.element().children[0].nodeName).toEqual('SPAN'); |
| 1617 | expect(l.element().children[0].textContent).toEqual('Baum--'); |
| 1618 | l.add(['Fragezeichen']); |
| 1619 | expect(l.element().children.length).toEqual(2); |
| 1620 | expect(l.element().children[1].nodeName).toEqual('SPAN'); |
| 1621 | expect(l.element().children[1].textContent).toEqual('Fragezeichen--'); |
| 1622 | }); |
| 1623 | |
| 1624 | it('should be correctly initializable', function () { |
| 1625 | var list = [ |
| 1626 | ["Constituency"], |
| 1627 | ["Lemma"], |
| 1628 | ["Morphology"], |
| 1629 | ["Part-of-Speech"], |
| 1630 | ["Syntax"] |
| 1631 | ]; |
| 1632 | |
| 1633 | var menu = KorAP.OwnMenu.create(list); |
| 1634 | |
| 1635 | expect(menu.lengthField().element().children.length).toEqual(5); |
| 1636 | }); |
| 1637 | }); |
| 1638 | |
| 1639 | describe('KorAP.Slider', function () { |
| 1640 | |
| 1641 | var demolonglist = [ |
| 1642 | ['Titel', 'title'], |
| 1643 | ['Untertitel', 'subTitle'], |
| 1644 | ['Veröffentlichungsdatum', 'pubDate'], |
| 1645 | ['Länge', 'length'], |
| 1646 | ['Autor', 'author'], |
| 1647 | ['Genre', 'genre'], |
| 1648 | ['corpusID', 'corpusID'], |
| 1649 | ['docID', 'docID'], |
| 1650 | ['textID', 'textID'], |
| 1651 | ]; |
| 1652 | |
| 1653 | it('should correctly be initializable', function () { |
| 1654 | var list = [ |
| 1655 | ["Constituency"], |
| 1656 | ["Lemma"], |
| 1657 | ["Morphology"], |
| 1658 | ["Part-of-Speech"], |
| 1659 | ["Syntax"] |
| 1660 | ]; |
| 1661 | |
| 1662 | var menu = KorAP.OwnMenu.create(list); |
| 1663 | |
| 1664 | menu._firstActive = true; |
| 1665 | menu.limit(3); |
| 1666 | |
| 1667 | expect(menu.show()).toBe(true); |
| 1668 | |
| 1669 | expect(menu.shownItem(0).active()).toBe(true); |
| 1670 | expect(menu.shownItem(1).active()).toBe(false); |
| 1671 | expect(menu.shownItem(2).active()).toBe(false); |
| 1672 | expect(menu.slider().offset()).toEqual(0); |
| 1673 | expect(menu.position).toEqual(0); |
| 1674 | }); |
| 1675 | |
| 1676 | it('should correctly move on arrow keys', function () { |
| 1677 | var list = [ |
| 1678 | ["Constituency"], |
| 1679 | ["Lemma"], |
| 1680 | ["Morphology"], |
| 1681 | ["Part-of-Speech"], |
| 1682 | ["Syntax"] |
| 1683 | ]; |
| 1684 | |
| 1685 | var menu = KorAP.OwnMenu.create(list); |
| 1686 | |
| 1687 | menu._firstActive = true; |
| 1688 | menu.limit(3); |
| 1689 | |
| 1690 | expect(menu.show()).toBe(true); |
| 1691 | |
| 1692 | menu.next(); |
| 1693 | expect(menu.shownItem(0).active()).toBe(false); |
| 1694 | expect(menu.shownItem(1).active()).toBe(true); |
| 1695 | expect(menu.shownItem(2).active()).toBe(false); |
| 1696 | expect(menu.slider().offset()).toEqual(0); |
| 1697 | expect(menu.position).toEqual(1); |
| 1698 | |
| 1699 | menu.next(); |
| 1700 | expect(menu.shownItem(0).active()).toBe(false); |
| 1701 | expect(menu.shownItem(1).active()).toBe(false); |
| 1702 | expect(menu.shownItem(2).active()).toBe(true); |
| 1703 | expect(menu.slider().offset()).toEqual(0); |
| 1704 | expect(menu.position).toEqual(2); |
| 1705 | |
| 1706 | menu.next(); |
| 1707 | expect(menu.shownItem(0).active()).toBe(false); |
| 1708 | expect(menu.shownItem(1).active()).toBe(false); |
| 1709 | expect(menu.shownItem(2).active()).toBe(true); |
| 1710 | expect(menu.slider().offset()).toEqual(1); |
| 1711 | expect(menu.position).toEqual(3); |
| 1712 | |
| 1713 | menu.next(); |
| 1714 | expect(menu.shownItem(0).active()).toBe(false); |
| 1715 | expect(menu.shownItem(1).active()).toBe(false); |
| 1716 | expect(menu.shownItem(2).active()).toBe(true); |
| 1717 | expect(menu.slider().offset()).toEqual(2); |
| 1718 | expect(menu.position).toEqual(4); |
| 1719 | |
| 1720 | menu.next(); |
| 1721 | expect(menu.shownItem(0).active()).toBe(true); |
| 1722 | expect(menu.shownItem(1).active()).toBe(false); |
| 1723 | expect(menu.shownItem(2).active()).toBe(false); |
| 1724 | expect(menu.slider().offset()).toEqual(0); |
| 1725 | expect(menu.position).toEqual(0); |
| 1726 | |
| 1727 | expect(menu.slider()._slider.style.height).toEqual('60%'); |
| 1728 | }); |
| 1729 | |
| 1730 | it('should correctly resize on prefixing', function () { |
| 1731 | var menu = KorAP.OwnMenu.create(demolonglist); |
| 1732 | menu._firstActive = true; |
| 1733 | menu.limit(3); |
| 1734 | |
| 1735 | expect(menu.show()).toBe(true); |
| 1736 | expect(menu.slider().offset()).toEqual(0); |
| 1737 | expect(menu.slider().length()).toEqual(9); |
| 1738 | |
| 1739 | expect(menu.prefix("e").show()).toBe(true); |
| 1740 | expect(menu.slider().length()).toEqual(6); |
| 1741 | |
| 1742 | expect(menu.prefix("el").show()).toBe(true); |
| 1743 | expect(menu.slider().length()).toEqual(2); |
| 1744 | |
| 1745 | expect(menu.prefix("e").show()).toBe(true); |
| 1746 | expect(menu.slider().length()).toEqual(6); |
| 1747 | |
| 1748 | expect(menu.prefix("").show()).toBe(true); |
| 1749 | expect(menu.slider().length()).toEqual(9); |
| 1750 | }); |
| 1751 | |
| 1752 | |
| 1753 | it('should correctly move the list on mousemove', function () { |
| 1754 | var list = [ |
| 1755 | ["Constituency"], |
| 1756 | ["Lemma"], |
| 1757 | ["Morphology"], |
| 1758 | ["Part-of-Speech"], |
| 1759 | ["Syntax"] |
| 1760 | ]; |
| 1761 | |
| 1762 | var menu = KorAP.OwnMenu.create(list); |
| 1763 | |
| 1764 | menu._firstActive = true; |
| 1765 | menu.limit(3); |
| 1766 | |
| 1767 | expect(menu.show()).toBe(true); |
| 1768 | |
| 1769 | expect(menu.shownItem(0).active()).toBe(true); |
| 1770 | expect(menu.shownItem(1).active()).toBe(false); |
| 1771 | expect(menu.shownItem(2).active()).toBe(false); |
| 1772 | expect(menu.slider().offset()).toEqual(0); |
| 1773 | |
| 1774 | // This will normally be done on |
| 1775 | menu.slider()._rulerHeight = 100; |
| 1776 | menu.slider()._sliderHeight = 40; |
| 1777 | menu.slider()._event.initOffset = 0; |
| 1778 | expect(menu.slider().length()).toEqual(5); |
| 1779 | |
| 1780 | menu.slider().movetoRel(10); |
| 1781 | expect(menu.slider().offset()).toEqual(0); |
| 1782 | |
| 1783 | expect(menu.shownItem(0).active()).toBe(true); |
| 1784 | expect(menu.shownItem(0).lcField()).toEqual(' constituency'); |
| 1785 | menu.slider().movetoRel(24); |
| 1786 | expect(menu.slider().offset()).toEqual(0); |
| 1787 | menu.slider().movetoRel(25); |
| 1788 | expect(menu.slider().offset()).toEqual(0); |
| 1789 | |
| 1790 | menu.slider().movetoRel(30); |
| 1791 | expect(menu.slider().offset()).toEqual(1); |
| 1792 | menu.slider().movetoRel(59); |
| 1793 | expect(menu.slider().offset()).toEqual(1); |
| 1794 | expect(menu.shownItem(0).active()).toBe(false); |
| 1795 | expect(menu.shownItem(0).lcField()).toEqual(' lemma'); |
| 1796 | |
| 1797 | // Everything > 60 is offset 2 |
| 1798 | menu.slider().movetoRel(60); |
| 1799 | expect(menu.slider().offset()).toEqual(2); |
| 1800 | menu.slider().movetoRel(180); |
| 1801 | expect(menu.slider().offset()).toEqual(2); |
| 1802 | expect(menu.shownItem(0).active()).toBe(false); |
| 1803 | expect(menu.shownItem(0).lcField()).toEqual(' morphology'); |
| 1804 | |
| 1805 | expect(menu.shownItem(1).active()).toBe(false); |
| 1806 | expect(menu.shownItem(2).active()).toBe(false); |
| 1807 | |
| 1808 | // When the active cursor moves again - scroll to viewport |
| 1809 | // cursor is before viewport |
| 1810 | menu.next(); |
| 1811 | expect(menu.shownItem(0).active()).toBe(true); |
| 1812 | expect(menu.shownItem(0).lcField()).toEqual(' lemma'); |
| 1813 | expect(menu.shownItem(1).active()).toBe(false); |
| 1814 | expect(menu.shownItem(2).active()).toBe(false); |
| 1815 | |
| 1816 | menu.next(); |
| 1817 | menu.next(); |
| 1818 | expect(menu.shownItem(0).active()).toBe(false); |
| 1819 | expect(menu.shownItem(0).lcField()).toEqual(' lemma'); |
| 1820 | expect(menu.shownItem(1).active()).toBe(false); |
| 1821 | expect(menu.shownItem(1).lcField()).toEqual(' morphology'); |
| 1822 | expect(menu.shownItem(2).active()).toBe(true); |
| 1823 | expect(menu.shownItem(2).lcField()).toEqual(' part-of-speech'); |
| 1824 | |
| 1825 | menu.slider().movetoRel(0); |
| 1826 | expect(menu.slider().offset()).toEqual(0); |
| 1827 | expect(menu.shownItem(0).active()).toBe(false); |
| 1828 | expect(menu.shownItem(0).lcField()).toEqual(' constituency'); |
| 1829 | expect(menu.shownItem(1).active()).toBe(false); |
| 1830 | expect(menu.shownItem(1).lcField()).toEqual(' lemma'); |
| 1831 | expect(menu.shownItem(2).active()).toBe(false); |
| 1832 | expect(menu.shownItem(2).lcField()).toEqual(' morphology'); |
| 1833 | |
| 1834 | // cursor is after viewport |
| 1835 | menu.next(); |
| 1836 | expect(menu.slider().offset()).toEqual(2); |
| 1837 | expect(menu.shownItem(0).active()).toBe(false); |
| 1838 | expect(menu.shownItem(0).lcField()).toEqual(' morphology'); |
| 1839 | expect(menu.shownItem(1).active()).toBe(false); |
| 1840 | expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech'); |
| 1841 | expect(menu.shownItem(2).active()).toBe(true); |
| 1842 | expect(menu.shownItem(2).lcField()).toEqual(' syntax'); |
| 1843 | |
| 1844 | menu.slider().movetoRel(0); |
| 1845 | expect(menu.slider().offset()).toEqual(0); |
| 1846 | expect(menu.shownItem(0).active()).toBe(false); |
| 1847 | expect(menu.shownItem(0).lcField()).toEqual(' constituency'); |
| 1848 | expect(menu.shownItem(1).active()).toBe(false); |
| 1849 | expect(menu.shownItem(1).lcField()).toEqual(' lemma'); |
| 1850 | expect(menu.shownItem(2).active()).toBe(false); |
| 1851 | expect(menu.shownItem(2).lcField()).toEqual(' morphology'); |
| 1852 | |
| 1853 | menu.prev(); |
| 1854 | expect(menu.slider().offset()).toEqual(2); |
| 1855 | expect(menu.shownItem(0).lcField()).toEqual(' morphology'); |
| 1856 | expect(menu.shownItem(0).active()).toBe(false); |
| 1857 | expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech'); |
| 1858 | expect(menu.shownItem(1).active()).toBe(true); |
| 1859 | expect(menu.shownItem(2).lcField()).toEqual(' syntax'); |
| 1860 | expect(menu.shownItem(2).active()).toBe(false); |
| 1861 | |
| 1862 | menu.prev(); |
| 1863 | menu.prev(); |
| 1864 | expect(menu.slider().offset()).toEqual(1); |
| 1865 | expect(menu.shownItem(0).lcField()).toEqual(' lemma'); |
| 1866 | expect(menu.shownItem(0).active()).toBe(true); |
| 1867 | expect(menu.shownItem(1).lcField()).toEqual(' morphology'); |
| 1868 | expect(menu.shownItem(1).active()).toBe(false); |
| 1869 | expect(menu.shownItem(2).lcField()).toEqual(' part-of-speech'); |
| 1870 | expect(menu.shownItem(2).active()).toBe(false); |
| 1871 | |
| 1872 | menu.slider().movetoRel(100); |
| 1873 | expect(menu.slider().offset()).toEqual(2); |
| 1874 | expect(menu.shownItem(0).lcField()).toEqual(' morphology'); |
| 1875 | expect(menu.shownItem(0).active()).toBe(false); |
| 1876 | expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech'); |
| 1877 | expect(menu.shownItem(1).active()).toBe(false); |
| 1878 | expect(menu.shownItem(2).lcField()).toEqual(' syntax'); |
| 1879 | expect(menu.shownItem(2).active()).toBe(false); |
| 1880 | |
| 1881 | menu.prev(); |
| 1882 | expect(menu.slider().offset()).toEqual(0); |
| 1883 | expect(menu.shownItem(0).lcField()).toEqual(' constituency'); |
| 1884 | expect(menu.shownItem(0).active()).toBe(true); |
| 1885 | expect(menu.shownItem(1).lcField()).toEqual(' lemma'); |
| 1886 | expect(menu.shownItem(1).active()).toBe(false); |
| 1887 | expect(menu.shownItem(2).lcField()).toEqual(' morphology'); |
| 1888 | expect(menu.shownItem(2).active()).toBe(false); |
| 1889 | }); |
| 1890 | }); |
| 1891 | |
| 1892 | describe('KorAP.MenuBenchmark', function () { |
| 1893 | var menu = menuClass.create([ |
| 1894 | ['Titel', 'title'], |
| 1895 | ['Untertitel', 'subTitle'], |
| 1896 | ['Veröffentlichungsdatum', 'pubDate'], |
| 1897 | ['Länge', 'length'], |
| 1898 | ['Autor', 'author'] |
| 1899 | ]); |
| 1900 | |
| 1901 | menu.limit(3).show(); |
| 1902 | |
| 1903 | // Some actions |
| 1904 | menu.next(); |
| 1905 | menu.next(); |
| 1906 | menu.prev(); |
| 1907 | menu.prev(); |
| 1908 | menu.prev(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1909 | |
Akron | 3c2730f | 2016-05-24 15:08:29 +0200 | [diff] [blame] | 1910 | menu.pageDown(); |
Akron | 3c2730f | 2016-05-24 15:08:29 +0200 | [diff] [blame] | 1911 | menu.pageUp(); |
| 1912 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1913 | // There is no fourth item in the list! |
| 1914 | menu.prefix('e').show(4); |
Akron | 5a1f5bb | 2016-05-23 22:00:39 +0200 | [diff] [blame] | 1915 | menu.next(); |
| 1916 | menu.next(); |
Akron | 5a1f5bb | 2016-05-23 22:00:39 +0200 | [diff] [blame] | 1917 | menu.prev(); |
| 1918 | menu.prev(); |
Akron | 5a1f5bb | 2016-05-23 22:00:39 +0200 | [diff] [blame] | 1919 | menu.prev(); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 1920 | }); |
| 1921 | }); |