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 | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 422 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
| 423 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
| 424 | expect(menu.element().getElementsByTagName("li")[1].getAttribute("data-action")).toEqual("l="); |
| 425 | expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 426 | expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 427 | |
| 428 | // Check boundaries |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 429 | expect(menu.element().getElementsByTagName("li")[0].classList.contains("no-more")).toBe(true); |
| 430 | expect(menu.element().getElementsByTagName("li")[1].classList.contains("no-more")).toBe(false); |
| 431 | expect(menu.element().getElementsByTagName("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"); |
| 439 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
| 440 | expect(menu.element().getElementsByTagName("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.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>"); |
| 442 | expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 443 | |
| 444 | // Check boundaries |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 445 | expect(menu.element().getElementsByTagName("li")[0].classList.contains("no-more")).toBe(true); |
| 446 | expect(menu.element().getElementsByTagName("li")[1].classList.contains("no-more")).toBe(false); |
| 447 | expect(menu.element().getElementsByTagName("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"); |
| 453 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
| 454 | expect(menu.element().getElementsByTagName("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.element().getElementsByTagName("li")[2]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 456 | |
| 457 | // Check boundaries |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 458 | expect(menu.element().getElementsByTagName("li")[0].classList.contains("no-more")).toBe(true); |
| 459 | expect(menu.element().getElementsByTagName("li")[1].classList.contains("no-more")).toBe(false); |
| 460 | expect(menu.element().getElementsByTagName("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"); |
| 464 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
| 465 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
| 466 | expect(menu.element().getElementsByTagName("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"); |
| 471 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Ex<mark>a</mark>mple 1</span>"); |
| 472 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Lemm<mark>a</mark></strong>"); |
| 473 | expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Ex<mark>a</mark>mple 2</span>"); |
| 474 | expect(menu.element().getElementsByTagName("li")[3].innerHTML).toEqual("<strong>P<mark>a</mark>rt-of-Speech</strong>"); |
| 475 | expect(menu.element().getElementsByTagName("li")[4].innerHTML).toEqual("<strong>Synt<mark>a</mark>x</strong>"); |
| 476 | expect(menu.element().getElementsByTagName("li")[5]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 477 | }); |
| 478 | |
| 479 | |
| 480 | it('should be nextable', function () { |
| 481 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 482 | menu._firstActive = true; |
| 483 | |
| 484 | // Show only 3 items |
| 485 | menu.limit(3); |
| 486 | expect(menu.show()).toBe(true); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 487 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 488 | expect(menu.shownItem(0).active()).toBe(true); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 489 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 490 | expect(menu.shownItem(1).active()).toBe(false); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 491 | expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 492 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 493 | expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 494 | |
| 495 | // Activate next (1) |
| 496 | menu.next(); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 497 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 498 | expect(menu.shownItem(0).active()).toBe(false); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 499 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 500 | expect(menu.shownItem(1).active()).toBe(true); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 501 | expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 502 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 503 | expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 504 | |
| 505 | // Activate next (2) |
| 506 | menu.next(); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 507 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 508 | expect(menu.shownItem(0).active()).toBe(false); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 509 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 510 | expect(menu.shownItem(1).active()).toBe(false); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 511 | expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 512 | expect(menu.shownItem(2).active()).toBe(true); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 513 | expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 514 | |
| 515 | // Activate next (3) |
| 516 | // scroll! |
| 517 | menu.next(); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 518 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Lemma</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 519 | expect(menu.shownItem(0).active()).toBe(false); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 520 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 521 | expect(menu.shownItem(1).active()).toBe(false); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 522 | expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 523 | expect(menu.shownItem(2).active()).toBe(true); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 524 | expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 525 | |
| 526 | // Activate next (4) |
| 527 | menu.next(); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 528 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 529 | expect(menu.shownItem(0).active()).toBe(false); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 530 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 531 | expect(menu.shownItem(1).active()).toBe(false); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 532 | expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Syntax</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 533 | expect(menu.shownItem(2).active()).toBe(true); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 534 | expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 535 | |
| 536 | // Activate next (5) - ROLL |
| 537 | menu.next(); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 538 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 539 | expect(menu.shownItem(0).active()).toBe(true); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 540 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 541 | expect(menu.shownItem(1).active()).toBe(false); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 542 | expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 543 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 544 | expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 545 | |
| 546 | // Active next (6) |
| 547 | menu.next(); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 548 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 549 | expect(menu.shownItem(0).active()).toBe(false); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 550 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 551 | expect(menu.shownItem(1).active()).toBe(true); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 552 | expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 553 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 554 | expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 555 | }); |
| 556 | |
| 557 | it('should be nextable without active field', function () { |
| 558 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 559 | menu.limit(3); |
| 560 | expect(menu.show()).toBe(true); |
| 561 | menu.next(); |
| 562 | expect(menu.shownItem(0).active()).toEqual(true); |
| 563 | }); |
| 564 | |
| 565 | |
| 566 | it('should be prevable', function () { |
| 567 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 568 | menu._firstActive = true; |
| 569 | menu.limit(3); |
| 570 | expect(menu.show()).toBe(true); |
| 571 | |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 572 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 573 | expect(menu.shownItem(0).active()).toBe(true); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 574 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 575 | expect(menu.shownItem(1).active()).toBe(false); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 576 | expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 577 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 578 | expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 579 | |
| 580 | // Activate prev (1) - roll to bottom |
| 581 | menu.prev(); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 582 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 583 | expect(menu.shownItem(0).active()).toBe(false); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 584 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 585 | expect(menu.shownItem(1).active()).toBe(false); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 586 | expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Syntax</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 587 | expect(menu.shownItem(2).active()).toBe(true); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 588 | expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 589 | |
| 590 | // Activate prev (2) |
| 591 | menu.prev(); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 592 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 593 | expect(menu.shownItem(0).active()).toBe(false); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 594 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 595 | expect(menu.shownItem(1).active()).toBe(true); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 596 | expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Syntax</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 597 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 598 | expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 599 | |
| 600 | // Activate prev (3) |
| 601 | menu.prev(); |
| 602 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
| 603 | expect(menu.shownItem(0).active()).toBe(true); |
| 604 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
| 605 | expect(menu.shownItem(1).active()).toBe(false); |
| 606 | expect(menu.shownItem(2).name()).toEqual("Syntax"); |
| 607 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 608 | expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 609 | |
| 610 | // Activate prev (4) |
| 611 | menu.prev(); |
| 612 | expect(menu.shownItem(0).name()).toEqual("Lemma"); |
| 613 | expect(menu.shownItem(0).active()).toBe(true); |
| 614 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
| 615 | expect(menu.shownItem(1).active()).toBe(false); |
| 616 | expect(menu.shownItem(2).name()).toEqual("Part-of-Speech"); |
| 617 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 618 | expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 619 | |
| 620 | // Activate prev (5) |
| 621 | menu.prev(); |
| 622 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
| 623 | expect(menu.shownItem(0).active()).toBe(true); |
| 624 | expect(menu.shownItem(1).name()).toEqual("Lemma"); |
| 625 | expect(menu.shownItem(1).active()).toBe(false); |
| 626 | expect(menu.shownItem(2).name()).toEqual("Morphology"); |
| 627 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 628 | expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 629 | |
| 630 | // Activate next (1) |
| 631 | menu.next(); |
| 632 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
| 633 | expect(menu.shownItem(0).active()).toBe(false); |
| 634 | expect(menu.shownItem(1).name()).toEqual("Lemma"); |
| 635 | expect(menu.shownItem(1).active()).toBe(true); |
| 636 | expect(menu.shownItem(2).name()).toEqual("Morphology"); |
| 637 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 638 | expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 639 | |
| 640 | // Activate prev (6) |
| 641 | menu.prev(); |
| 642 | |
| 643 | // Activate prev (7) |
| 644 | menu.prev(); |
| 645 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
| 646 | expect(menu.shownItem(0).active()).toBe(false); |
| 647 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
| 648 | expect(menu.shownItem(1).active()).toBe(false); |
| 649 | expect(menu.shownItem(2).name()).toEqual("Syntax"); |
| 650 | expect(menu.shownItem(2).active()).toBe(true); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 651 | expect(menu.element().getElementsByTagName("li")[3]).toBe(undefined); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 652 | }); |
| 653 | |
| 654 | it('should be prevable without active field', function () { |
| 655 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 656 | menu.limit(3); |
| 657 | expect(menu.show()).toBe(true); |
| 658 | menu.prev(); |
| 659 | expect(menu.shownItem(2).active()).toEqual(true); |
| 660 | expect(menu.shownItem(2).lcField()).toEqual(' syntax'); |
| 661 | }); |
| 662 | |
| 663 | it('should be navigatable and filterable (prefix = "o")', function () { |
| 664 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 665 | menu._firstActive = true; |
| 666 | menu.limit(2); |
| 667 | |
| 668 | expect(menu.prefix("o").show()).toBe(true); |
| 669 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 670 | expect(menu.element().getElementsByTagName("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] | 671 | expect(menu.shownItem(0).active()).toBe(true); |
| 672 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 673 | expect(menu.element().getElementsByTagName("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] | 674 | expect(menu.shownItem(1).active()).toBe(false); |
| 675 | expect(menu.shownItem(2)).toBe(undefined); |
| 676 | |
| 677 | // Next (1) |
| 678 | menu.next(); |
| 679 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 680 | expect(menu.element().getElementsByTagName("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] | 681 | expect(menu.shownItem(0).active()).toBe(false); |
| 682 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 683 | expect(menu.element().getElementsByTagName("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] | 684 | expect(menu.shownItem(1).active()).toBe(true); |
| 685 | expect(menu.shownItem(2)).toBe(undefined); |
| 686 | |
| 687 | // Next (2) |
| 688 | menu.next(); |
| 689 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 690 | expect(menu.element().getElementsByTagName("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] | 691 | expect(menu.shownItem(0).active()).toBe(false); |
| 692 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 693 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 694 | expect(menu.shownItem(1).active()).toBe(true); |
| 695 | expect(menu.shownItem(2)).toBe(undefined); |
| 696 | |
| 697 | // Next (3) - to prefix |
| 698 | menu.next(); |
| 699 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 700 | expect(menu.element().getElementsByTagName("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] | 701 | expect(menu.shownItem(0).active()).toBe(false); |
| 702 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 703 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 704 | expect(menu.shownItem(1).active()).toBe(false); |
| 705 | expect(menu.shownItem(2)).toBe(undefined); |
| 706 | |
| 707 | menu.next(); |
| 708 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 709 | expect(menu.element().getElementsByTagName("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] | 710 | expect(menu.shownItem(0).active()).toBe(true); |
| 711 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 712 | expect(menu.element().getElementsByTagName("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] | 713 | expect(menu.shownItem(1).active()).toBe(false); |
| 714 | expect(menu.shownItem(2)).toBe(undefined); |
| 715 | }); |
| 716 | |
| 717 | |
| 718 | it('should be navigatable and filterable (prefix = "ex", "e")', function () { |
| 719 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 720 | menu._firstActive = true; |
| 721 | |
| 722 | menu.limit(2); |
| 723 | expect(menu.prefix("ex").show()).toBe(true); |
| 724 | |
| 725 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 726 | expect(menu.element().getElementsByTagName("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] | 727 | expect(menu.shownItem(0).active()).toBe(true); |
| 728 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 729 | expect(menu.element().getElementsByTagName("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] | 730 | expect(menu.shownItem(1).active()).toBe(false); |
| 731 | expect(menu.shownItem(2)).toBe(undefined); |
| 732 | |
| 733 | // Next (1) |
| 734 | menu.next(); |
| 735 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 736 | expect(menu.element().getElementsByTagName("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] | 737 | expect(menu.shownItem(0).active()).toBe(false); |
| 738 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 739 | expect(menu.element().getElementsByTagName("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] | 740 | expect(menu.shownItem(1).active()).toBe(true); |
| 741 | expect(menu.shownItem(2)).toBe(undefined); |
| 742 | |
| 743 | // Next (2) |
| 744 | menu.next(); |
| 745 | |
| 746 | expect(menu.prefix()).toEqual('ex'); |
| 747 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 748 | expect(menu.element().getElementsByTagName("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] | 749 | expect(menu.shownItem(0).active()).toBe(false); |
| 750 | |
| 751 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 752 | expect(menu.element().getElementsByTagName("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] | 753 | expect(menu.shownItem(1).active()).toBe(false); |
| 754 | expect(menu.shownItem(2)).toBe(undefined); |
| 755 | |
| 756 | // Reset limit |
| 757 | menu.limit(5); |
| 758 | |
| 759 | // Change show |
| 760 | expect(menu.prefix("e").show()).toBe(true); |
| 761 | expect(menu._prefix.active()).toBe(false); |
| 762 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 763 | expect(menu.element().getElementsByTagName("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] | 764 | expect(menu.shownItem(0).active()).toBe(true); |
| 765 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 766 | expect(menu.element().getElementsByTagName("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] | 767 | expect(menu.shownItem(1).active()).toBe(false); |
| 768 | expect(menu.shownItem(2)).toBe(undefined); |
| 769 | |
| 770 | // Next (1) |
| 771 | menu.next(); |
| 772 | expect(menu._prefix.active()).toBe(false); |
| 773 | expect(menu.prefix()).toEqual('e'); |
| 774 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 775 | expect(menu.element().getElementsByTagName("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] | 776 | expect(menu.shownItem(0).active()).toBe(false); |
| 777 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 778 | expect(menu.element().getElementsByTagName("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] | 779 | expect(menu.shownItem(1).active()).toBe(true); |
| 780 | expect(menu.shownItem(2)).toBe(undefined); |
| 781 | |
| 782 | // Next (2) |
| 783 | menu.next(); |
| 784 | expect(menu._prefix.active()).toBe(true); |
| 785 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 786 | expect(menu.element().getElementsByTagName("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] | 787 | expect(menu.shownItem(0).active()).toBe(false); |
| 788 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 789 | expect(menu.element().getElementsByTagName("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] | 790 | expect(menu.shownItem(1).active()).toBe(false); |
| 791 | expect(menu.shownItem(2)).toBe(undefined); |
| 792 | |
| 793 | // Next (3) |
| 794 | menu.next(); |
| 795 | expect(menu._prefix.active()).toBe(false); |
| 796 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 797 | expect(menu.element().getElementsByTagName("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] | 798 | expect(menu.shownItem(0).active()).toBe(true); |
| 799 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 800 | expect(menu.element().getElementsByTagName("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] | 801 | expect(menu.shownItem(1).active()).toBe(false); |
| 802 | expect(menu.shownItem(2)).toBe(undefined); |
| 803 | }); |
| 804 | |
Akron | acffc65 | 2017-12-18 21:21:25 +0100 | [diff] [blame] | 805 | it('should be filterable (multiple prefix = "pro sin")', function () { |
| 806 | var menu = KorAP.HintMenu.create("drukola/p=", listMultiPrefix); |
| 807 | menu._firstActive = true; |
| 808 | |
| 809 | menu.limit(2); |
| 810 | expect(menu.prefix("pro sin").show()).toBe(true); |
| 811 | expect(menu.shownItem(0).name()).toEqual("PPS"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 812 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual( |
Akron | acffc65 | 2017-12-18 21:21:25 +0100 | [diff] [blame] | 813 | "<strong>PPS</strong><span>Personal <mark>Pro</mark>noun, <mark>Sin</mark>gular</span>" |
| 814 | ); |
| 815 | |
| 816 | expect(menu.shownItem(0).active()).toBe(true); |
| 817 | expect(menu.shownItem(1).name()).toEqual("PPSA"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 818 | expect(menu.element().getElementsByTagName("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] | 819 | expect(menu.shownItem(1).active()).toBe(false); |
| 820 | |
| 821 | expect(menu.shownItem(2)).toBe(undefined); |
| 822 | }); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 823 | |
Akron | 359c7e1 | 2017-12-19 12:06:55 +0100 | [diff] [blame] | 824 | it('should be filterable (trimming = " p")', function () { |
| 825 | var menu = KorAP.HintMenu.create("/p=", listMultiPrefix); |
| 826 | // menu._firstActive = true; |
| 827 | |
| 828 | menu.limit(2); |
| 829 | expect(menu.show()).toBe(true); |
| 830 | menu._prefix.add(" "); |
| 831 | expect(menu.show()).toBe(true); |
| 832 | menu._prefix.add("p") |
| 833 | expect(menu.show()).toBe(true); |
| 834 | expect(menu.shownItem(0).name()).toEqual("PP"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 835 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual( |
Akron | 359c7e1 | 2017-12-19 12:06:55 +0100 | [diff] [blame] | 836 | "<strong><mark>P</mark><mark>P</mark></strong>"+ |
| 837 | "<span><mark>P</mark>ersonal <mark>P</mark>ronoun</span>" |
| 838 | ); |
| 839 | }); |
| 840 | |
| 841 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 842 | it('should choose prefix with failing prefix (1)', function () { |
| 843 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 844 | menu.limit(2); |
| 845 | expect(menu.prefix("exit").show()).toBe(true); |
| 846 | expect(menu.element().querySelector('li')).toBe(null); |
| 847 | expect(menu.shownItem(0)).toBeUndefined(); |
| 848 | expect(menu._prefix.active()).toBe(true); |
| 849 | }); |
| 850 | |
| 851 | |
| 852 | it('should choose prefix with failing prefix (2)', function () { |
| 853 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 854 | menu.limit(2); |
| 855 | expect(menu.show()).toBe(true); |
| 856 | expect(menu.prefix("exit").show()).toBe(true); |
| 857 | expect(menu.element().querySelector('li')).toBe(null); |
| 858 | expect(menu.shownItem(0)).toBeUndefined(); |
| 859 | expect(menu._prefix.active()).toBe(true); |
| 860 | }); |
| 861 | |
| 862 | it('should ignore navigation with failing prefix', function () { |
| 863 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 864 | menu.limit(2); |
| 865 | expect(menu.show()).toBe(true); |
| 866 | |
| 867 | menu.next(); |
| 868 | |
| 869 | expect(menu.prefix("exit").show()).toBe(true); |
| 870 | expect(menu.element().querySelector('li')).toBe(null); |
| 871 | expect(menu.shownItem(0)).toBeUndefined(); |
| 872 | expect(menu._prefix.active()).toBe(true); |
| 873 | |
| 874 | menu.next(); |
| 875 | expect(menu._prefix.active()).toBe(true); |
| 876 | |
| 877 | menu.prev(); |
| 878 | expect(menu._prefix.active()).toBe(true); |
| 879 | |
| 880 | }); |
| 881 | |
| 882 | it('should be navigatable with prefix', function () { |
| 883 | var menu = KorAP.HintMenu.create("cnx/", demolist); |
| 884 | menu._firstActive = true; |
| 885 | |
| 886 | menu.limit(3); |
| 887 | |
| 888 | expect(menu.show()).toBe(true); |
| 889 | expect(menu.prefix()).toEqual(""); |
| 890 | |
| 891 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 892 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 893 | expect(menu.shownItem(0).active()).toBe(true); |
| 894 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 895 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 896 | expect(menu.shownItem(1).active()).toBe(false); |
| 897 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 898 | expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 899 | expect(menu.shownItem(2).active()).toBe(false); |
| 900 | expect(menu.shownItem(3)).toBe(undefined); |
| 901 | |
| 902 | menu._prefix.add('a'); |
| 903 | expect(menu.show()).toBe(true); |
| 904 | expect(menu.prefix()).toEqual("a"); |
| 905 | expect(menu.shownItem(0).name()).toEqual("Autor"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 906 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 907 | |
| 908 | menu._prefix.add('u'); |
| 909 | expect(menu.show()).toBe(true); |
| 910 | expect(menu.prefix()).toEqual("au"); |
| 911 | expect(menu.shownItem(0).name()).toEqual("Autor"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 912 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong><mark>Au</mark>tor</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 913 | |
| 914 | menu._prefix.chop(); |
| 915 | expect(menu.show()).toBe(true); |
| 916 | expect(menu.prefix()).toEqual("a"); |
| 917 | expect(menu.shownItem(0).name()).toEqual("Autor"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 918 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 919 | |
| 920 | menu._prefix.chop(); |
| 921 | expect(menu.show()).toBe(true); |
| 922 | expect(menu.prefix()).toEqual(""); |
| 923 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 924 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 925 | expect(menu.shownItem(0).active()).toBe(true); |
| 926 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 927 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 928 | expect(menu.shownItem(1).active()).toBe(false); |
| 929 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 930 | expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 931 | expect(menu.shownItem(2).active()).toBe(false); |
| 932 | expect(menu.shownItem(3)).toBe(undefined); |
| 933 | |
| 934 | // Forward |
| 935 | menu._prefix.chop(); |
| 936 | expect(menu.show()).toBe(true); |
| 937 | expect(menu.prefix()).toEqual(""); |
| 938 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 939 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 940 | expect(menu.shownItem(0).active()).toBe(true); |
| 941 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 942 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 943 | expect(menu.shownItem(1).active()).toBe(false); |
| 944 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 945 | expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 946 | expect(menu.shownItem(2).active()).toBe(false); |
| 947 | |
| 948 | // Forward |
| 949 | menu.next(); |
| 950 | expect(menu.prefix()).toEqual(""); |
| 951 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 952 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 953 | expect(menu.shownItem(0).active()).toBe(false); |
| 954 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 955 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 956 | expect(menu.shownItem(1).active()).toBe(true); |
| 957 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 958 | expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 959 | expect(menu.shownItem(2).active()).toBe(false); |
| 960 | expect(menu.shownItem(3)).toBe(undefined); |
| 961 | |
| 962 | // Forward |
| 963 | menu.next(); |
| 964 | expect(menu.prefix()).toEqual(""); |
| 965 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 966 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 967 | expect(menu.shownItem(0).active()).toBe(false); |
| 968 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 969 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 970 | expect(menu.shownItem(1).active()).toBe(false); |
| 971 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 972 | expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 973 | expect(menu.shownItem(2).active()).toBe(true); |
| 974 | expect(menu.shownItem(3)).toBe(undefined); |
| 975 | |
| 976 | // Forward |
| 977 | menu.next(); |
| 978 | expect(menu.prefix()).toEqual(""); |
| 979 | expect(menu.shownItem(0).name()).toEqual("Untertitel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 980 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 981 | expect(menu.shownItem(0).active()).toBe(false); |
| 982 | expect(menu.shownItem(1).name()).toEqual("Veröffentlichungsdatum"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 983 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 984 | expect(menu.shownItem(1).active()).toBe(false); |
| 985 | expect(menu.shownItem(2).name()).toEqual("Länge"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 986 | expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Länge</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 987 | expect(menu.shownItem(2).active()).toBe(true); |
| 988 | expect(menu.shownItem(3)).toBe(undefined); |
| 989 | |
| 990 | // Forward |
| 991 | menu.next(); |
| 992 | expect(menu.prefix()).toEqual(""); |
| 993 | expect(menu.shownItem(0).name()).toEqual("Veröffentlichungsdatum"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 994 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 995 | expect(menu.shownItem(0).active()).toBe(false); |
| 996 | expect(menu.shownItem(1).name()).toEqual("Länge"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 997 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Länge</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 998 | expect(menu.shownItem(1).active()).toBe(false); |
| 999 | expect(menu.shownItem(2).name()).toEqual("Autor"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 1000 | expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Autor</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1001 | expect(menu.shownItem(2).active()).toBe(true); |
| 1002 | expect(menu.shownItem(3)).toBe(undefined); |
| 1003 | |
| 1004 | // Forward |
| 1005 | menu.next(); |
| 1006 | expect(menu.prefix()).toEqual(""); |
| 1007 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 1008 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Titel</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1009 | expect(menu.shownItem(0).active()).toBe(true); |
| 1010 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 1011 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1012 | expect(menu.shownItem(1).active()).toBe(false); |
| 1013 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 1014 | expect(menu.element().getElementsByTagName("li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1015 | expect(menu.shownItem(2).active()).toBe(false); |
| 1016 | }); |
| 1017 | |
| 1018 | |
| 1019 | it('should be navigatable with a prefix (1)', function () { |
| 1020 | var menu = KorAP.HintMenu.create("cnx/", demolist); |
| 1021 | menu._firstActive = true; |
| 1022 | |
| 1023 | menu.limit(3); |
| 1024 | |
| 1025 | expect(menu.show()).toBe(true); |
| 1026 | expect(menu.prefix()).toEqual(""); |
| 1027 | |
| 1028 | // Add prefix in uppercase - but check in lowercase |
| 1029 | menu.prefix('El'); |
| 1030 | expect(menu.show()).toBe(true); |
| 1031 | |
| 1032 | expect(menu.prefix()).toEqual("El"); |
| 1033 | expect(menu._prefix.active()).toEqual(false); |
| 1034 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 1035 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1036 | expect(menu.shownItem(0).active()).toBe(true); |
| 1037 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 1038 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1039 | expect(menu.shownItem(1).active()).toBe(false); |
| 1040 | expect(menu.shownItem(2)).toBe(undefined); |
| 1041 | |
| 1042 | // Forward |
| 1043 | menu.next(); |
| 1044 | expect(menu.prefix()).toEqual("El"); |
| 1045 | expect(menu._prefix.active()).toEqual(false); |
| 1046 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 1047 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1048 | expect(menu.shownItem(0).active()).toBe(false); |
| 1049 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 1050 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1051 | expect(menu.shownItem(1).active()).toBe(true); |
| 1052 | expect(menu.shownItem(2)).toBe(undefined); |
| 1053 | |
| 1054 | // Forward |
| 1055 | menu.next(); |
| 1056 | expect(menu.prefix()).toEqual("El"); |
| 1057 | expect(menu._prefix.active()).toEqual(true); |
| 1058 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 1059 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1060 | expect(menu.shownItem(0).active()).toBe(false); |
| 1061 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 1062 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1063 | expect(menu.shownItem(1).active()).toBe(false); |
| 1064 | expect(menu.shownItem(2)).toBe(undefined); |
| 1065 | |
| 1066 | // Backward |
| 1067 | menu.prev(); |
| 1068 | expect(menu.prefix()).toEqual("El"); |
| 1069 | expect(menu._prefix.active()).toEqual(false); |
| 1070 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 1071 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1072 | expect(menu.shownItem(0).active()).toBe(false); |
| 1073 | |
| 1074 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 1075 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1076 | expect(menu.shownItem(1).active()).toBe(true); |
| 1077 | expect(menu.shownItem(2)).toBe(undefined); |
| 1078 | }); |
| 1079 | |
| 1080 | |
| 1081 | it('should be navigatable with a prefix (2)', function () { |
| 1082 | var menu = KorAP.HintMenu.create("cnx/", demolist); |
| 1083 | menu._firstActive = true; |
| 1084 | |
| 1085 | menu.limit(3); |
| 1086 | expect(menu.show()).toBe(true); |
| 1087 | expect(menu.prefix()).toEqual(""); |
| 1088 | menu.prefix('el'); |
| 1089 | expect(menu.show()).toBe(true); |
| 1090 | |
| 1091 | expect(menu.prefix()).toEqual("el"); |
| 1092 | expect(menu._prefix.active()).toEqual(false); |
| 1093 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 1094 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1095 | expect(menu.shownItem(0).active()).toBe(true); |
| 1096 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 1097 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1098 | expect(menu.shownItem(1).active()).toBe(false); |
| 1099 | expect(menu.shownItem(2)).toBe(undefined); |
| 1100 | |
| 1101 | // Backward |
| 1102 | menu.prev(); |
| 1103 | expect(menu._prefix.active()).toEqual(true); |
| 1104 | |
| 1105 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 1106 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1107 | expect(menu.shownItem(0).active()).toBe(false); |
| 1108 | |
| 1109 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 1110 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1111 | expect(menu.shownItem(1).active()).toBe(false); |
| 1112 | expect(menu.shownItem(2)).toBe(undefined); |
| 1113 | |
| 1114 | // Backward |
| 1115 | menu.prev(); |
| 1116 | expect(menu._prefix.active()).toEqual(false); |
| 1117 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 1118 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1119 | expect(menu.shownItem(0).active()).toBe(false); |
| 1120 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 1121 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1122 | expect(menu.shownItem(1).active()).toBe(true); |
| 1123 | expect(menu.shownItem(2)).toBe(undefined); |
| 1124 | }); |
| 1125 | |
| 1126 | it('should be navigatable with a prefix (3)', function () { |
| 1127 | var menu = KorAP.HintMenu.create("cnx/", demolist); |
| 1128 | menu._firstActive = true; |
| 1129 | menu.limit(3); |
| 1130 | expect(menu.show()).toBe(true); |
| 1131 | expect(menu.prefix()).toEqual(""); |
| 1132 | menu.prefix('el'); |
| 1133 | expect(menu.show()).toBe(true); |
| 1134 | |
| 1135 | expect(menu.prefix()).toEqual("el"); |
| 1136 | expect(menu._prefix.active()).toEqual(false); |
| 1137 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 1138 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1139 | expect(menu.shownItem(0).active()).toBe(true); |
| 1140 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 1141 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1142 | expect(menu.shownItem(1).active()).toBe(false); |
| 1143 | expect(menu.shownItem(2)).toBe(undefined); |
| 1144 | |
| 1145 | // Backward |
| 1146 | menu.prev(); |
| 1147 | expect(menu._prefix.active()).toEqual(true); |
| 1148 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 1149 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1150 | expect(menu.shownItem(0).active()).toBe(false); |
| 1151 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 1152 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1153 | expect(menu.shownItem(1).active()).toBe(false); |
| 1154 | expect(menu.shownItem(2)).toBe(undefined); |
| 1155 | |
| 1156 | |
| 1157 | // Forward |
| 1158 | menu.next(); |
| 1159 | expect(menu.prefix()).toEqual("el"); |
| 1160 | expect(menu._prefix.active()).toEqual(false); |
| 1161 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 1162 | expect(menu.element().getElementsByTagName("li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1163 | expect(menu.shownItem(0).active()).toBe(true); |
| 1164 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | 524320f | 2021-05-14 11:33:09 +0200 | [diff] [blame] | 1165 | expect(menu.element().getElementsByTagName("li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1166 | expect(menu.shownItem(1).active()).toBe(false); |
| 1167 | expect(menu.shownItem(2)).toBe(undefined); |
| 1168 | |
| 1169 | }); |
| 1170 | |
| 1171 | it('should show screens by offset', function () { |
| 1172 | var menu = KorAP.HintMenu.create('cnx/', demolist); |
| 1173 | menu.limit(3); |
| 1174 | expect(menu.show()).toBe(true); |
| 1175 | |
| 1176 | expect(menu.shownItem(0).active()).toBe(false); |
| 1177 | expect(menu.shownItem(1).active()).toBe(false); |
| 1178 | expect(menu.shownItem(2).active()).toBe(false); |
| 1179 | |
| 1180 | // Highlight the first entry |
| 1181 | menu.next(); |
| 1182 | |
| 1183 | expect(menu.shownItem(0).active()).toBe(true); |
| 1184 | expect(menu.shownItem(1).active()).toBe(false); |
| 1185 | expect(menu.shownItem(2).active()).toBe(false); |
| 1186 | |
| 1187 | // Highlight the second entry |
| 1188 | menu.next(); |
| 1189 | |
| 1190 | expect(menu.shownItem(0).active()).toBe(false); |
| 1191 | expect(menu.shownItem(1).active()).toBe(true); |
| 1192 | expect(menu.shownItem(2).active()).toBe(false); |
| 1193 | expect(menu.shownItem(3)).toBe(undefined); |
| 1194 | |
| 1195 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1196 | expect(menu.shownItem(1).lcField()).toEqual(' untertitel'); |
| 1197 | |
| 1198 | // Move to first screen |
| 1199 | menu.screen(0); |
| 1200 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1201 | expect(menu.shownItem(1).lcField()).toEqual(' untertitel'); |
| 1202 | expect(menu.shownItem(0).active()).toBe(false); |
| 1203 | expect(menu.shownItem(1).active()).toBe(true); |
| 1204 | expect(menu.shownItem(2).active()).toBe(false); |
| 1205 | expect(menu.shownItem(3)).toBe(undefined); |
| 1206 | |
| 1207 | // Move to second screen |
| 1208 | menu.screen(1); |
| 1209 | expect(menu.shownItem(0).lcField()).toEqual(' untertitel'); |
| 1210 | expect(menu.shownItem(0).active()).toBe(true); |
| 1211 | expect(menu.shownItem(1).active()).toBe(false); |
| 1212 | expect(menu.shownItem(2).active()).toBe(false); |
| 1213 | expect(menu.shownItem(3)).toBe(undefined); |
| 1214 | |
| 1215 | menu.screen(2); |
| 1216 | expect(menu.shownItem(0).lcField()).toEqual(' veröffentlichungsdatum'); |
| 1217 | expect(menu.shownItem(0).active()).toBe(false); |
| 1218 | expect(menu.shownItem(1).active()).toBe(false); |
| 1219 | expect(menu.shownItem(2).active()).toBe(false); |
| 1220 | expect(menu.shownItem(3)).toBe(undefined); |
| 1221 | |
| 1222 | menu.screen(1); |
| 1223 | expect(menu.shownItem(0).lcField()).toEqual(' untertitel'); |
| 1224 | expect(menu.shownItem(0).active()).toBe(true); |
| 1225 | expect(menu.shownItem(1).active()).toBe(false); |
| 1226 | expect(menu.shownItem(2).active()).toBe(false); |
| 1227 | expect(menu.shownItem(3)).toBe(undefined); |
| 1228 | }); |
| 1229 | |
| 1230 | it('should show screens by offset when prefixed', function () { |
| 1231 | var menu = KorAP.HintMenu.create('cnx/', demolist); |
| 1232 | menu.limit(3); |
| 1233 | expect(menu.prefix("e").show()).toBe(true); |
| 1234 | expect(menu.shownItem(0).active()).toBe(false); |
| 1235 | expect(menu.shownItem(1).active()).toBe(false); |
| 1236 | expect(menu.shownItem(2).active()).toBe(false); |
| 1237 | |
| 1238 | expect(menu.shownItem(0).element().innerHTML).toEqual('<strong>Tit<mark>e</mark>l</strong>'); |
| 1239 | menu.screen(1); |
| 1240 | expect(menu.shownItem(0).element().innerHTML).toEqual('<strong>Unt<mark>e</mark>rtit<mark>e</mark>l</strong>'); |
| 1241 | }); |
| 1242 | |
| 1243 | |
| 1244 | it('should be page downable', function () { |
| 1245 | var menu = KorAP.OwnMenu.create(demolonglist); |
| 1246 | menu.limit(3); |
| 1247 | |
| 1248 | expect(menu.show(0)).toBe(true); |
| 1249 | |
| 1250 | expect(menu.shownItem(0).active()).toBe(true); |
| 1251 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1252 | expect(menu.shownItem(1).active()).toBe(false); |
| 1253 | expect(menu.shownItem(2).active()).toBe(false); |
| 1254 | expect(menu.shownItem(3)).toBe(undefined); |
| 1255 | |
| 1256 | menu.pageDown(); |
| 1257 | |
| 1258 | expect(menu.shownItem(0).lcField()).toEqual(' länge'); |
| 1259 | expect(menu.shownItem(0).active()).toBe(false); |
| 1260 | expect(menu.shownItem(1).active()).toBe(false); |
| 1261 | expect(menu.shownItem(2).active()).toBe(false); |
| 1262 | |
| 1263 | menu.pageDown(); |
| 1264 | |
| 1265 | expect(menu.shownItem(0).lcField()).toEqual(' corpusid'); |
| 1266 | expect(menu.shownItem(0).active()).toBe(false); |
| 1267 | expect(menu.shownItem(1).active()).toBe(false); |
| 1268 | expect(menu.shownItem(2).active()).toBe(false); |
| 1269 | |
| 1270 | // Doesn't matter |
| 1271 | menu.pageDown(); |
| 1272 | |
| 1273 | expect(menu.shownItem(0).lcField()).toEqual(' corpusid'); |
| 1274 | expect(menu.shownItem(0).active()).toBe(false); |
| 1275 | expect(menu.shownItem(1).active()).toBe(false); |
| 1276 | expect(menu.shownItem(2).active()).toBe(false); |
| 1277 | }); |
| 1278 | |
| 1279 | it('should be page downable with prefix', function () { |
| 1280 | var menu = KorAP.OwnMenu.create(demolonglist); |
| 1281 | menu.limit(3); |
| 1282 | |
| 1283 | expect(menu.prefix('e').show(0)).toBe(true); |
| 1284 | |
| 1285 | expect(menu.shownItem(0).active()).toBe(true); |
| 1286 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1287 | expect(menu.shownItem(1).active()).toBe(false); |
| 1288 | expect(menu.shownItem(1).lcField()).toEqual(' untertitel'); |
| 1289 | expect(menu.shownItem(2).active()).toBe(false); |
| 1290 | expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum'); |
| 1291 | expect(menu.shownItem(3)).toBe(undefined); |
| 1292 | |
| 1293 | menu.pageDown(); |
| 1294 | |
| 1295 | expect(menu.shownItem(0).active()).toBe(false); |
| 1296 | expect(menu.shownItem(0).lcField()).toEqual(' länge'); |
| 1297 | expect(menu.shownItem(1).active()).toBe(false); |
| 1298 | expect(menu.shownItem(1).lcField()).toEqual(' genre'); |
| 1299 | expect(menu.shownItem(2).active()).toBe(false); |
| 1300 | expect(menu.shownItem(2).lcField()).toEqual(' textid'); |
| 1301 | |
| 1302 | // Doesn't matter |
| 1303 | menu.pageDown(); |
| 1304 | |
| 1305 | expect(menu.shownItem(0).active()).toBe(false); |
| 1306 | expect(menu.shownItem(0).lcField()).toEqual(' länge'); |
| 1307 | expect(menu.shownItem(1).active()).toBe(false); |
| 1308 | expect(menu.shownItem(1).lcField()).toEqual(' genre'); |
| 1309 | expect(menu.shownItem(2).active()).toBe(false); |
| 1310 | expect(menu.shownItem(2).lcField()).toEqual(' textid'); |
| 1311 | }); |
| 1312 | |
| 1313 | |
| 1314 | it('should be page upable', function () { |
| 1315 | var menu = KorAP.OwnMenu.create(demolonglist); |
| 1316 | menu.limit(3); |
| 1317 | |
| 1318 | // Choose the final value |
| 1319 | expect(menu.show(1000)).toBe(true); |
| 1320 | |
| 1321 | expect(menu.shownItem(0).active()).toBe(false); |
| 1322 | expect(menu.shownItem(1).active()).toBe(false); |
| 1323 | expect(menu.shownItem(2).active()).toBe(true); |
| 1324 | expect(menu.shownItem(2).lcField()).toEqual(' textid'); |
| 1325 | expect(menu.shownItem(3)).toBe(undefined); |
| 1326 | |
| 1327 | menu.pageUp(); |
| 1328 | |
| 1329 | expect(menu.shownItem(0).lcField()).toEqual(' länge'); |
| 1330 | expect(menu.shownItem(0).active()).toBe(false); |
| 1331 | expect(menu.shownItem(1).active()).toBe(false); |
| 1332 | expect(menu.shownItem(2).active()).toBe(false); |
| 1333 | |
| 1334 | menu.pageUp(); |
| 1335 | |
| 1336 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1337 | expect(menu.shownItem(0).active()).toBe(false); |
| 1338 | expect(menu.shownItem(1).active()).toBe(false); |
| 1339 | expect(menu.shownItem(2).active()).toBe(false); |
| 1340 | |
| 1341 | // Doesn't matter |
| 1342 | menu.pageUp(); |
| 1343 | |
| 1344 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1345 | expect(menu.shownItem(0).active()).toBe(false); |
| 1346 | expect(menu.shownItem(1).active()).toBe(false); |
| 1347 | expect(menu.shownItem(2).active()).toBe(false); |
| 1348 | }); |
| 1349 | |
| 1350 | it('should be page upable with prefix', function () { |
| 1351 | var menu = KorAP.OwnMenu.create(demolonglist); |
| 1352 | menu.limit(3); |
| 1353 | |
| 1354 | // Choose the final value |
| 1355 | expect(menu.prefix("e").show(1000)).toBe(true); |
| 1356 | |
| 1357 | expect(menu.shownItem(0).active()).toBe(false); |
| 1358 | expect(menu.shownItem(0).lcField()).toEqual(' länge'); |
| 1359 | expect(menu.shownItem(1).active()).toBe(false); |
| 1360 | expect(menu.shownItem(1).lcField()).toEqual(' genre'); |
| 1361 | expect(menu.shownItem(2).active()).toBe(true); |
| 1362 | expect(menu.shownItem(2).lcField()).toEqual(' textid'); |
| 1363 | expect(menu.shownItem(3)).toBe(undefined); |
| 1364 | |
| 1365 | menu.pageUp(); |
| 1366 | |
| 1367 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1368 | expect(menu.shownItem(0).active()).toBe(false); |
| 1369 | expect(menu.shownItem(1).active()).toBe(false); |
| 1370 | expect(menu.shownItem(1).lcField()).toEqual(' untertitel'); |
| 1371 | expect(menu.shownItem(2).active()).toBe(false); |
| 1372 | expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum'); |
| 1373 | |
| 1374 | // Doesn't matter |
| 1375 | menu.pageUp(); |
| 1376 | |
| 1377 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1378 | expect(menu.shownItem(0).active()).toBe(false); |
| 1379 | expect(menu.shownItem(1).active()).toBe(false); |
| 1380 | expect(menu.shownItem(1).lcField()).toEqual(' untertitel'); |
| 1381 | expect(menu.shownItem(2).active()).toBe(false); |
| 1382 | expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum'); |
| 1383 | }); |
| 1384 | |
Akron | e817b88 | 2018-08-31 14:09:17 +0200 | [diff] [blame] | 1385 | it('should be view upable and downable (1)', function () { |
| 1386 | var menu = KorAP.OwnMenu.create(demolonglist); |
| 1387 | menu.limit(7); |
| 1388 | |
| 1389 | // Choose the final value |
| 1390 | expect(menu.show(1)).toBe(true); |
| 1391 | |
| 1392 | expect(menu.shownItem(0).active()).toBe(false); |
| 1393 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1394 | expect(menu.shownItem(1).active()).toBe(true); |
| 1395 | expect(menu.shownItem(2).active()).toBe(false); |
| 1396 | expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum'); |
| 1397 | expect(menu.shownItem(6).active()).toBe(false); |
| 1398 | expect(menu.shownItem(7)).toBe(undefined); |
| 1399 | |
| 1400 | // Doesn't change anything |
| 1401 | menu.viewUp(); |
| 1402 | |
| 1403 | expect(menu.shownItem(0).active()).toBe(false); |
| 1404 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1405 | expect(menu.shownItem(1).active()).toBe(true); |
| 1406 | |
| 1407 | menu.viewDown(); |
| 1408 | |
| 1409 | expect(menu.shownItem(0).active()).toBe(true); |
| 1410 | expect(menu.shownItem(0).lcField()).toEqual(' untertitel'); |
| 1411 | expect(menu.shownItem(1).active()).toBe(false); |
| 1412 | |
| 1413 | menu.viewDown(); |
| 1414 | |
| 1415 | expect(menu.shownItem(0).active()).toBe(false); |
| 1416 | expect(menu.shownItem(0).lcField()).toEqual(' veröffentlichungsdatum'); |
| 1417 | expect(menu.shownItem(1).active()).toBe(false); |
| 1418 | |
| 1419 | // No effect anymore |
| 1420 | menu.viewDown(); |
| 1421 | |
| 1422 | expect(menu.shownItem(0).active()).toBe(false); |
| 1423 | expect(menu.shownItem(0).lcField()).toEqual(' veröffentlichungsdatum'); |
| 1424 | expect(menu.shownItem(1).active()).toBe(false); |
| 1425 | }); |
| 1426 | |
| 1427 | it('should be view upable and downable (2)', function () { |
| 1428 | |
| 1429 | // List is longer than limit |
| 1430 | var menu = KorAP.OwnMenu.create(demolist); |
| 1431 | menu.limit(7); |
| 1432 | |
| 1433 | // Choose the final value |
| 1434 | expect(menu.show(1)).toBe(true); |
| 1435 | |
| 1436 | expect(menu.shownItem(0).active()).toBe(false); |
| 1437 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1438 | expect(menu.shownItem(1).active()).toBe(true); |
| 1439 | expect(menu.shownItem(2).active()).toBe(false); |
| 1440 | expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum'); |
| 1441 | expect(menu.shownItem(4).active()).toBe(false); |
| 1442 | expect(menu.shownItem(5)).toBe(undefined); |
| 1443 | |
| 1444 | // Doesn't change anything |
| 1445 | menu.viewUp(); |
| 1446 | |
| 1447 | expect(menu.shownItem(0).active()).toBe(false); |
| 1448 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1449 | expect(menu.shownItem(1).active()).toBe(true); |
| 1450 | |
| 1451 | menu.viewDown(); |
| 1452 | |
| 1453 | expect(menu.shownItem(0).active()).toBe(false); |
| 1454 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1455 | expect(menu.shownItem(1).active()).toBe(true); |
| 1456 | }); |
| 1457 | |
| 1458 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1459 | it('should scroll to a chosen value (1)', function () { |
| 1460 | var menu = KorAP.OwnMenu.create(demolist); |
| 1461 | menu.limit(3); |
| 1462 | |
| 1463 | // Choose value 1 |
| 1464 | expect(menu.show(1)).toBe(true); |
| 1465 | |
| 1466 | expect(menu.shownItem(0).active()).toBe(false); |
| 1467 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1468 | expect(menu.shownItem(1).active()).toBe(true); |
| 1469 | expect(menu.shownItem(2).active()).toBe(false); |
| 1470 | expect(menu.shownItem(3)).toBe(undefined); |
| 1471 | |
| 1472 | // Choose value 2 |
| 1473 | expect(menu.show(2)).toBe(true); |
| 1474 | |
| 1475 | expect(menu.shownItem(0).active()).toBe(false); |
| 1476 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1477 | expect(menu.shownItem(1).active()).toBe(false); |
| 1478 | expect(menu.shownItem(2).active()).toBe(true); |
| 1479 | expect(menu.shownItem(3)).toBe(undefined); |
| 1480 | }); |
| 1481 | |
| 1482 | it('should scroll to a chosen value (2)', function () { |
| 1483 | var menu = KorAP.OwnMenu.create(demolonglist); |
| 1484 | |
| 1485 | // Choose value 3 |
| 1486 | expect(menu.limit(3).show(3)).toBe(true); |
| 1487 | expect(menu.shownItem(0).lcField()).toEqual(' länge'); |
| 1488 | expect(menu.shownItem(0).active()).toBe(true); |
| 1489 | expect(menu.shownItem(1).active()).toBe(false); |
| 1490 | expect(menu.shownItem(2).active()).toBe(false); |
| 1491 | expect(menu.shownItem(3)).toBe(undefined); |
| 1492 | }); |
| 1493 | |
| 1494 | xit('should scroll to a chosen value after prefixing, if the chosen value is live'); |
| 1495 | }); |
| 1496 | |
| 1497 | describe('KorAP.Prefix', function () { |
| 1498 | it('should be initializable', function () { |
| 1499 | var p = prefixClass.create(); |
| 1500 | expect(p.element().classList.contains('pref')).toBeTruthy(); |
| 1501 | expect(p.isSet()).not.toBeTruthy(); |
| 1502 | |
| 1503 | /* |
| 1504 | expect(mi.lcField()).toEqual(' baum'); |
| 1505 | */ |
| 1506 | |
| 1507 | }); |
| 1508 | |
| 1509 | it('should be modifiable', function () { |
| 1510 | var p = prefixClass.create(); |
| 1511 | expect(p.value()).toEqual(''); |
| 1512 | expect(p.element().firstChild).toBeNull(); |
| 1513 | |
| 1514 | // Set string |
| 1515 | expect(p.value('Test')).toEqual('Test'); |
| 1516 | expect(p.value()).toEqual('Test'); |
| 1517 | expect(p.element().firstChild.nodeValue).toEqual('Test'); |
| 1518 | |
| 1519 | // Add string |
| 1520 | expect(p.add('ified')).toEqual('Testified'); |
| 1521 | expect(p.value()).toEqual('Testified'); |
| 1522 | expect(p.element().firstChild.nodeValue).toEqual('Testified'); |
| 1523 | |
| 1524 | // Clear string |
| 1525 | p.clear(); |
| 1526 | expect(p.value()).toEqual(''); |
| 1527 | expect(p.element().firstChild).toBeNull(); |
| 1528 | |
| 1529 | // Set string |
| 1530 | expect(p.value('Test')).toEqual('Test'); |
| 1531 | expect(p.value()).toEqual('Test'); |
| 1532 | expect(p.element().firstChild.nodeValue).toEqual('Test'); |
| 1533 | |
| 1534 | expect(p.chop()).toEqual('Tes'); |
| 1535 | expect(p.value()).toEqual('Tes'); |
| 1536 | expect(p.element().firstChild.nodeValue).toEqual('Tes'); |
| 1537 | |
| 1538 | expect(p.chop()).toEqual('Te'); |
| 1539 | expect(p.value()).toEqual('Te'); |
| 1540 | expect(p.element().firstChild.nodeValue).toEqual('Te'); |
| 1541 | |
| 1542 | expect(p.chop()).toEqual('T'); |
| 1543 | expect(p.value()).toEqual('T'); |
| 1544 | expect(p.element().firstChild.nodeValue).toEqual('T'); |
| 1545 | |
| 1546 | expect(p.chop()).toEqual(''); |
| 1547 | expect(p.value()).toEqual(''); |
| 1548 | expect(p.element().firstChild).toBeNull(); |
| 1549 | }); |
| 1550 | |
| 1551 | it('should be activatable', function () { |
| 1552 | var p = prefixClass.create(); |
| 1553 | expect(p.value()).toEqual(''); |
| 1554 | expect(p.element().firstChild).toBeNull(); |
| 1555 | |
| 1556 | expect(p.value('Test')).toEqual('Test'); |
| 1557 | expect(p.element().firstChild.nodeValue).toEqual('Test'); |
| 1558 | |
| 1559 | expect(p.active()).not.toBeTruthy(); |
| 1560 | expect(p.element().classList.contains('active')).not.toBeTruthy(); |
| 1561 | |
| 1562 | p.active(true); |
| 1563 | expect(p.active()).toBeTruthy(); |
| 1564 | expect(p.element().classList.contains('active')).toBeTruthy(); |
| 1565 | }); |
| 1566 | }); |
| 1567 | |
| 1568 | describe('KorAP.LengthField', function () { |
| 1569 | it('should be initializable', function () { |
| 1570 | var l = lengthFieldClass.create(); |
| 1571 | expect(l.element().classList.contains('lengthField')).toBeTruthy(); |
| 1572 | expect(l.element().children.length).toEqual(0); |
| 1573 | }); |
| 1574 | |
| 1575 | it('should be extensible', function () { |
| 1576 | var l = lengthFieldClass.create(); |
| 1577 | l.add(['Baum']); |
| 1578 | expect(l.element().children.length).toEqual(1); |
| 1579 | expect(l.element().children[0].nodeName).toEqual('SPAN'); |
| 1580 | expect(l.element().children[0].textContent).toEqual('Baum--'); |
| 1581 | l.add(['Fragezeichen']); |
| 1582 | expect(l.element().children.length).toEqual(2); |
| 1583 | expect(l.element().children[1].nodeName).toEqual('SPAN'); |
| 1584 | expect(l.element().children[1].textContent).toEqual('Fragezeichen--'); |
| 1585 | }); |
| 1586 | |
| 1587 | it('should be correctly initializable', function () { |
| 1588 | var list = [ |
| 1589 | ["Constituency"], |
| 1590 | ["Lemma"], |
| 1591 | ["Morphology"], |
| 1592 | ["Part-of-Speech"], |
| 1593 | ["Syntax"] |
| 1594 | ]; |
| 1595 | |
| 1596 | var menu = KorAP.OwnMenu.create(list); |
| 1597 | |
| 1598 | expect(menu.lengthField().element().children.length).toEqual(5); |
| 1599 | }); |
| 1600 | }); |
| 1601 | |
| 1602 | describe('KorAP.Slider', function () { |
| 1603 | |
| 1604 | var demolonglist = [ |
| 1605 | ['Titel', 'title'], |
| 1606 | ['Untertitel', 'subTitle'], |
| 1607 | ['Veröffentlichungsdatum', 'pubDate'], |
| 1608 | ['Länge', 'length'], |
| 1609 | ['Autor', 'author'], |
| 1610 | ['Genre', 'genre'], |
| 1611 | ['corpusID', 'corpusID'], |
| 1612 | ['docID', 'docID'], |
| 1613 | ['textID', 'textID'], |
| 1614 | ]; |
| 1615 | |
| 1616 | it('should correctly be initializable', function () { |
| 1617 | var list = [ |
| 1618 | ["Constituency"], |
| 1619 | ["Lemma"], |
| 1620 | ["Morphology"], |
| 1621 | ["Part-of-Speech"], |
| 1622 | ["Syntax"] |
| 1623 | ]; |
| 1624 | |
| 1625 | var menu = KorAP.OwnMenu.create(list); |
| 1626 | |
| 1627 | menu._firstActive = true; |
| 1628 | menu.limit(3); |
| 1629 | |
| 1630 | expect(menu.show()).toBe(true); |
| 1631 | |
| 1632 | expect(menu.shownItem(0).active()).toBe(true); |
| 1633 | expect(menu.shownItem(1).active()).toBe(false); |
| 1634 | expect(menu.shownItem(2).active()).toBe(false); |
| 1635 | expect(menu.slider().offset()).toEqual(0); |
| 1636 | expect(menu.position).toEqual(0); |
| 1637 | }); |
| 1638 | |
| 1639 | it('should correctly move on arrow keys', function () { |
| 1640 | var list = [ |
| 1641 | ["Constituency"], |
| 1642 | ["Lemma"], |
| 1643 | ["Morphology"], |
| 1644 | ["Part-of-Speech"], |
| 1645 | ["Syntax"] |
| 1646 | ]; |
| 1647 | |
| 1648 | var menu = KorAP.OwnMenu.create(list); |
| 1649 | |
| 1650 | menu._firstActive = true; |
| 1651 | menu.limit(3); |
| 1652 | |
| 1653 | expect(menu.show()).toBe(true); |
| 1654 | |
| 1655 | menu.next(); |
| 1656 | expect(menu.shownItem(0).active()).toBe(false); |
| 1657 | expect(menu.shownItem(1).active()).toBe(true); |
| 1658 | expect(menu.shownItem(2).active()).toBe(false); |
| 1659 | expect(menu.slider().offset()).toEqual(0); |
| 1660 | expect(menu.position).toEqual(1); |
| 1661 | |
| 1662 | menu.next(); |
| 1663 | expect(menu.shownItem(0).active()).toBe(false); |
| 1664 | expect(menu.shownItem(1).active()).toBe(false); |
| 1665 | expect(menu.shownItem(2).active()).toBe(true); |
| 1666 | expect(menu.slider().offset()).toEqual(0); |
| 1667 | expect(menu.position).toEqual(2); |
| 1668 | |
| 1669 | menu.next(); |
| 1670 | expect(menu.shownItem(0).active()).toBe(false); |
| 1671 | expect(menu.shownItem(1).active()).toBe(false); |
| 1672 | expect(menu.shownItem(2).active()).toBe(true); |
| 1673 | expect(menu.slider().offset()).toEqual(1); |
| 1674 | expect(menu.position).toEqual(3); |
| 1675 | |
| 1676 | menu.next(); |
| 1677 | expect(menu.shownItem(0).active()).toBe(false); |
| 1678 | expect(menu.shownItem(1).active()).toBe(false); |
| 1679 | expect(menu.shownItem(2).active()).toBe(true); |
| 1680 | expect(menu.slider().offset()).toEqual(2); |
| 1681 | expect(menu.position).toEqual(4); |
| 1682 | |
| 1683 | menu.next(); |
| 1684 | expect(menu.shownItem(0).active()).toBe(true); |
| 1685 | expect(menu.shownItem(1).active()).toBe(false); |
| 1686 | expect(menu.shownItem(2).active()).toBe(false); |
| 1687 | expect(menu.slider().offset()).toEqual(0); |
| 1688 | expect(menu.position).toEqual(0); |
| 1689 | |
| 1690 | expect(menu.slider()._slider.style.height).toEqual('60%'); |
| 1691 | }); |
| 1692 | |
| 1693 | it('should correctly resize on prefixing', function () { |
| 1694 | var menu = KorAP.OwnMenu.create(demolonglist); |
| 1695 | menu._firstActive = true; |
| 1696 | menu.limit(3); |
| 1697 | |
| 1698 | expect(menu.show()).toBe(true); |
| 1699 | expect(menu.slider().offset()).toEqual(0); |
| 1700 | expect(menu.slider().length()).toEqual(9); |
| 1701 | |
| 1702 | expect(menu.prefix("e").show()).toBe(true); |
| 1703 | expect(menu.slider().length()).toEqual(6); |
| 1704 | |
| 1705 | expect(menu.prefix("el").show()).toBe(true); |
| 1706 | expect(menu.slider().length()).toEqual(2); |
| 1707 | |
| 1708 | expect(menu.prefix("e").show()).toBe(true); |
| 1709 | expect(menu.slider().length()).toEqual(6); |
| 1710 | |
| 1711 | expect(menu.prefix("").show()).toBe(true); |
| 1712 | expect(menu.slider().length()).toEqual(9); |
| 1713 | }); |
| 1714 | |
| 1715 | |
| 1716 | it('should correctly move the list on mousemove', function () { |
| 1717 | var list = [ |
| 1718 | ["Constituency"], |
| 1719 | ["Lemma"], |
| 1720 | ["Morphology"], |
| 1721 | ["Part-of-Speech"], |
| 1722 | ["Syntax"] |
| 1723 | ]; |
| 1724 | |
| 1725 | var menu = KorAP.OwnMenu.create(list); |
| 1726 | |
| 1727 | menu._firstActive = true; |
| 1728 | menu.limit(3); |
| 1729 | |
| 1730 | expect(menu.show()).toBe(true); |
| 1731 | |
| 1732 | expect(menu.shownItem(0).active()).toBe(true); |
| 1733 | expect(menu.shownItem(1).active()).toBe(false); |
| 1734 | expect(menu.shownItem(2).active()).toBe(false); |
| 1735 | expect(menu.slider().offset()).toEqual(0); |
| 1736 | |
| 1737 | // This will normally be done on |
| 1738 | menu.slider()._rulerHeight = 100; |
| 1739 | menu.slider()._sliderHeight = 40; |
| 1740 | menu.slider()._event.initOffset = 0; |
| 1741 | expect(menu.slider().length()).toEqual(5); |
| 1742 | |
| 1743 | menu.slider().movetoRel(10); |
| 1744 | expect(menu.slider().offset()).toEqual(0); |
| 1745 | |
| 1746 | expect(menu.shownItem(0).active()).toBe(true); |
| 1747 | expect(menu.shownItem(0).lcField()).toEqual(' constituency'); |
| 1748 | menu.slider().movetoRel(24); |
| 1749 | expect(menu.slider().offset()).toEqual(0); |
| 1750 | menu.slider().movetoRel(25); |
| 1751 | expect(menu.slider().offset()).toEqual(0); |
| 1752 | |
| 1753 | menu.slider().movetoRel(30); |
| 1754 | expect(menu.slider().offset()).toEqual(1); |
| 1755 | menu.slider().movetoRel(59); |
| 1756 | expect(menu.slider().offset()).toEqual(1); |
| 1757 | expect(menu.shownItem(0).active()).toBe(false); |
| 1758 | expect(menu.shownItem(0).lcField()).toEqual(' lemma'); |
| 1759 | |
| 1760 | // Everything > 60 is offset 2 |
| 1761 | menu.slider().movetoRel(60); |
| 1762 | expect(menu.slider().offset()).toEqual(2); |
| 1763 | menu.slider().movetoRel(180); |
| 1764 | expect(menu.slider().offset()).toEqual(2); |
| 1765 | expect(menu.shownItem(0).active()).toBe(false); |
| 1766 | expect(menu.shownItem(0).lcField()).toEqual(' morphology'); |
| 1767 | |
| 1768 | expect(menu.shownItem(1).active()).toBe(false); |
| 1769 | expect(menu.shownItem(2).active()).toBe(false); |
| 1770 | |
| 1771 | // When the active cursor moves again - scroll to viewport |
| 1772 | // cursor is before viewport |
| 1773 | menu.next(); |
| 1774 | expect(menu.shownItem(0).active()).toBe(true); |
| 1775 | expect(menu.shownItem(0).lcField()).toEqual(' lemma'); |
| 1776 | expect(menu.shownItem(1).active()).toBe(false); |
| 1777 | expect(menu.shownItem(2).active()).toBe(false); |
| 1778 | |
| 1779 | menu.next(); |
| 1780 | menu.next(); |
| 1781 | expect(menu.shownItem(0).active()).toBe(false); |
| 1782 | expect(menu.shownItem(0).lcField()).toEqual(' lemma'); |
| 1783 | expect(menu.shownItem(1).active()).toBe(false); |
| 1784 | expect(menu.shownItem(1).lcField()).toEqual(' morphology'); |
| 1785 | expect(menu.shownItem(2).active()).toBe(true); |
| 1786 | expect(menu.shownItem(2).lcField()).toEqual(' part-of-speech'); |
| 1787 | |
| 1788 | menu.slider().movetoRel(0); |
| 1789 | expect(menu.slider().offset()).toEqual(0); |
| 1790 | expect(menu.shownItem(0).active()).toBe(false); |
| 1791 | expect(menu.shownItem(0).lcField()).toEqual(' constituency'); |
| 1792 | expect(menu.shownItem(1).active()).toBe(false); |
| 1793 | expect(menu.shownItem(1).lcField()).toEqual(' lemma'); |
| 1794 | expect(menu.shownItem(2).active()).toBe(false); |
| 1795 | expect(menu.shownItem(2).lcField()).toEqual(' morphology'); |
| 1796 | |
| 1797 | // cursor is after viewport |
| 1798 | menu.next(); |
| 1799 | expect(menu.slider().offset()).toEqual(2); |
| 1800 | expect(menu.shownItem(0).active()).toBe(false); |
| 1801 | expect(menu.shownItem(0).lcField()).toEqual(' morphology'); |
| 1802 | expect(menu.shownItem(1).active()).toBe(false); |
| 1803 | expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech'); |
| 1804 | expect(menu.shownItem(2).active()).toBe(true); |
| 1805 | expect(menu.shownItem(2).lcField()).toEqual(' syntax'); |
| 1806 | |
| 1807 | menu.slider().movetoRel(0); |
| 1808 | expect(menu.slider().offset()).toEqual(0); |
| 1809 | expect(menu.shownItem(0).active()).toBe(false); |
| 1810 | expect(menu.shownItem(0).lcField()).toEqual(' constituency'); |
| 1811 | expect(menu.shownItem(1).active()).toBe(false); |
| 1812 | expect(menu.shownItem(1).lcField()).toEqual(' lemma'); |
| 1813 | expect(menu.shownItem(2).active()).toBe(false); |
| 1814 | expect(menu.shownItem(2).lcField()).toEqual(' morphology'); |
| 1815 | |
| 1816 | menu.prev(); |
| 1817 | expect(menu.slider().offset()).toEqual(2); |
| 1818 | expect(menu.shownItem(0).lcField()).toEqual(' morphology'); |
| 1819 | expect(menu.shownItem(0).active()).toBe(false); |
| 1820 | expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech'); |
| 1821 | expect(menu.shownItem(1).active()).toBe(true); |
| 1822 | expect(menu.shownItem(2).lcField()).toEqual(' syntax'); |
| 1823 | expect(menu.shownItem(2).active()).toBe(false); |
| 1824 | |
| 1825 | menu.prev(); |
| 1826 | menu.prev(); |
| 1827 | expect(menu.slider().offset()).toEqual(1); |
| 1828 | expect(menu.shownItem(0).lcField()).toEqual(' lemma'); |
| 1829 | expect(menu.shownItem(0).active()).toBe(true); |
| 1830 | expect(menu.shownItem(1).lcField()).toEqual(' morphology'); |
| 1831 | expect(menu.shownItem(1).active()).toBe(false); |
| 1832 | expect(menu.shownItem(2).lcField()).toEqual(' part-of-speech'); |
| 1833 | expect(menu.shownItem(2).active()).toBe(false); |
| 1834 | |
| 1835 | menu.slider().movetoRel(100); |
| 1836 | expect(menu.slider().offset()).toEqual(2); |
| 1837 | expect(menu.shownItem(0).lcField()).toEqual(' morphology'); |
| 1838 | expect(menu.shownItem(0).active()).toBe(false); |
| 1839 | expect(menu.shownItem(1).lcField()).toEqual(' part-of-speech'); |
| 1840 | expect(menu.shownItem(1).active()).toBe(false); |
| 1841 | expect(menu.shownItem(2).lcField()).toEqual(' syntax'); |
| 1842 | expect(menu.shownItem(2).active()).toBe(false); |
| 1843 | |
| 1844 | menu.prev(); |
| 1845 | expect(menu.slider().offset()).toEqual(0); |
| 1846 | expect(menu.shownItem(0).lcField()).toEqual(' constituency'); |
| 1847 | expect(menu.shownItem(0).active()).toBe(true); |
| 1848 | expect(menu.shownItem(1).lcField()).toEqual(' lemma'); |
| 1849 | expect(menu.shownItem(1).active()).toBe(false); |
| 1850 | expect(menu.shownItem(2).lcField()).toEqual(' morphology'); |
| 1851 | expect(menu.shownItem(2).active()).toBe(false); |
| 1852 | }); |
| 1853 | }); |
| 1854 | |
| 1855 | describe('KorAP.MenuBenchmark', function () { |
| 1856 | var menu = menuClass.create([ |
| 1857 | ['Titel', 'title'], |
| 1858 | ['Untertitel', 'subTitle'], |
| 1859 | ['Veröffentlichungsdatum', 'pubDate'], |
| 1860 | ['Länge', 'length'], |
| 1861 | ['Autor', 'author'] |
| 1862 | ]); |
| 1863 | |
| 1864 | menu.limit(3).show(); |
| 1865 | |
| 1866 | // Some actions |
| 1867 | menu.next(); |
| 1868 | menu.next(); |
| 1869 | menu.prev(); |
| 1870 | menu.prev(); |
| 1871 | menu.prev(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1872 | |
Akron | 3c2730f | 2016-05-24 15:08:29 +0200 | [diff] [blame] | 1873 | menu.pageDown(); |
Akron | 3c2730f | 2016-05-24 15:08:29 +0200 | [diff] [blame] | 1874 | menu.pageUp(); |
| 1875 | |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 1876 | // There is no fourth item in the list! |
| 1877 | menu.prefix('e').show(4); |
Akron | 5a1f5bb | 2016-05-23 22:00:39 +0200 | [diff] [blame] | 1878 | menu.next(); |
| 1879 | menu.next(); |
Akron | 5a1f5bb | 2016-05-23 22:00:39 +0200 | [diff] [blame] | 1880 | menu.prev(); |
| 1881 | menu.prev(); |
Akron | 5a1f5bb | 2016-05-23 22:00:39 +0200 | [diff] [blame] | 1882 | menu.prev(); |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame] | 1883 | }); |
| 1884 | }); |