Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1 | define( |
| 2 | ['containermenu', 'menu/item', 'menu/prefix', 'menu/lengthField','container/containeritem','container/container'], |
| 3 | function (containerMenuClass, menuItemClass, prefixClass, lengthFieldClass, containerItemClass, containerClass) { |
Leo Repp | 46903bf | 2021-12-18 16:05:53 +0100 | [diff] [blame] | 4 | function emitKeyboardEvent (element, type, letter, keyCode) { |
| 5 | // ORIGINAL FROM hintSpec.js !!! |
| 6 | // event type : keydown, keyup, keypress |
| 7 | // http://stackoverflow.com/questions/596481/simulate-javascript-key-events |
| 8 | // http://stackoverflow.com/questions/961532/firing-a-keyboard-event-in-javascript |
| 9 | /** |
| 10 | * Nils Version. Does not work due to bug noted below |
| 11 | var keyboardEvent = document.createEvent("KeyboardEvent",); |
| 12 | var initMethod = typeof keyboardEvent.initKeyboardEvent !== 'undefined' ? |
| 13 | "initKeyboardEvent" : "initKeyEvent"; |
| 14 | keyboardEvent[initMethod]( |
| 15 | |
| 16 | |
| 17 | |
| 18 | type, |
| 19 | true, // bubbles |
| 20 | true, // cancelable |
| 21 | window, // viewArg: should be window |
| 22 | false, // ctrlKeyArg |
| 23 | false, // altKeyArg |
| 24 | false, // shiftKeyArg |
| 25 | false, // metaKeyArg |
| 26 | keyCode, // keyCodeArg : unsigned long the virtual key code, else 0 |
| 27 | charCode || 0 // charCodeArgs : unsigned long the Unicode character |
| 28 | // associated with the depressed key, else 0 |
| 29 | |
| 30 | ); |
| 31 | element.dispatchEvent(keyboardEvent); |
| 32 | */ |
| 33 | //Leos Version |
| 34 | //https://stackoverflow.com/a/59113178 |
| 35 | |
| 36 | //might not work on Chromium |
| 37 | element.dispatchEvent(new KeyboardEvent(type, { |
| 38 | key: letter, |
| 39 | keyCode: keyCode, |
| 40 | code: "Key"+letter, |
| 41 | which: keyCode, //This is a hack |
| 42 | shiftKey: false, |
| 43 | ctrlKey: false, |
| 44 | metaKey: false, |
| 45 | bubbles: true, |
| 46 | view: window, |
| 47 | charCode: keyCode //This is a hack https://bugs.webkit.org/show_bug.cgi?id=16735 |
| 48 | // charCodeArgs : unsigned long the Unicode character |
| 49 | // associated with the depressed key, else 0 |
| 50 | })); |
| 51 | // ORIGINAL FROM hintSpec.js !!! |
| 52 | }; |
| 53 | |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 54 | // The OwnMenu item |
| 55 | const OwnMenuItem = { |
| 56 | create : function (params) { |
| 57 | return Object.create(menuItemClass).upgradeTo(OwnMenuItem)._init(params); |
| 58 | }, |
| 59 | content : function (content) { |
| 60 | if (arguments.length === 1) { |
| 61 | this._content = content; |
| 62 | }; |
| 63 | return this._content; |
| 64 | }, |
| 65 | _init : function (params) { |
| 66 | if (params[0] === undefined) |
| 67 | throw new Error("Missing parameters"); |
| 68 | |
| 69 | this._content = document.createTextNode(params[0]); |
| 70 | this._lcField = ' ' + this.content().textContent.toLowerCase(); |
| 71 | |
| 72 | return this; |
| 73 | } |
| 74 | }; |
| 75 | |
| 76 | /** |
| 77 | * Create own conainerItem class. |
| 78 | */ |
| 79 | const OwnContainerItemClass = { |
| 80 | create : function () { |
| 81 | var obj = containerItemClass.create() |
| 82 | .upgradeTo(OwnContainerItemClass); |
| 83 | //._init(); |
| 84 | obj.value=""; |
| 85 | return obj; |
| 86 | }, |
| 87 | add : function (letter) { |
| 88 | this.value+=letter; |
| 89 | }, |
| 90 | clear : function () { |
| 91 | this.value = ""; |
| 92 | }, |
| 93 | further : function () { |
| 94 | this.value = this.value + this.value; |
| 95 | }, |
| 96 | onclick : function () { |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 97 | } |
| 98 | }; |
| 99 | |
| 100 | //List of items. |
| 101 | var ExampleItemList = new Array; |
Leo Repp | 5799740 | 2021-08-18 16:37:52 +0200 | [diff] [blame] | 102 | ExampleItemList.push({value : "CIValue1" , defaultTextValue : "CIText1 "}); |
| 103 | ExampleItemList.push({value : "CIValue2" , defaultTextValue : "CIText2 "}); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 104 | |
| 105 | //Own container class. |
| 106 | const OwnContainerClass = { |
| 107 | create : function (listOfContainerItems, params) { |
| 108 | //console.log(containerClass); |
| 109 | return containerClass.create(listOfContainerItems, params) |
| 110 | .upgradeTo(OwnContainerClass); |
| 111 | } |
| 112 | }; |
| 113 | |
| 114 | const OwnContainerMenu = { |
| 115 | create : function (list, containerList) { |
| 116 | const params = { |
| 117 | itemClass : OwnMenuItem, |
| 118 | prefixClass : prefixClass, |
| 119 | lengthFieldClass : lengthFieldClass, |
| 120 | containerClass : OwnContainerClass, |
| 121 | containerItemClass : OwnContainerItemClass |
| 122 | }; |
| 123 | var obj = containerMenuClass.create(list,params,containerList) |
| 124 | .upgradeTo(OwnContainerMenu); |
| 125 | //._init(list, params); |
| 126 | return obj; |
| 127 | } |
| 128 | }; |
| 129 | |
Leo Repp | c66268e | 2021-10-28 11:44:35 +0200 | [diff] [blame] | 130 | describe('KorAP.ContainerMenu', function () { |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 131 | |
| 132 | var list = [ |
| 133 | ["Constituency"], |
| 134 | ["Lemma"], |
| 135 | ["Morphology"], |
| 136 | ["Part-of-Speech"], |
| 137 | ["Syntax"] |
| 138 | ]; |
| 139 | |
| 140 | var listWithEX = [ |
| 141 | ["example 1 Constituency"], |
| 142 | ["Lemma"], |
| 143 | ["example 2 Morphology"], |
| 144 | ["Part-of_Speech"], |
| 145 | ["Syntax"] |
| 146 | ]; |
| 147 | |
| 148 | var listMultiPrefix = [ |
| 149 | ["Personal Pronoun"], |
| 150 | ["Personal Pronoun, Plural"], |
| 151 | ["Personal Pronoun, Plural, Acc."], |
| 152 | ["Personal Pronoun, Plural, Dative"], |
| 153 | ["Personal Pronoun, Plural, Direct"], |
| 154 | ["Personal Pronoun, Plural, Oblique"], |
| 155 | ["Personal Pronoun, Singular"], |
| 156 | ["Personal Pronoun, Singular, Accusative"], |
| 157 | ["Personal Pronoun, Singular, Dative"], |
| 158 | ["Personal Pronoun, Singular, Direct"], |
| 159 | ["Personal Pronoun, Singular, Nominative"], |
| 160 | ["Personal Pronoun, Singular, Oblique"] |
| 161 | ]; |
| 162 | |
| 163 | var demolist = [ |
| 164 | ['Titel'], |
| 165 | ['Untertitel'], |
| 166 | ['Veröffentlichungsdatum'], |
| 167 | ['Länge'], |
| 168 | ['Autor'] |
| 169 | ]; |
| 170 | |
| 171 | var demolonglist = [ |
| 172 | ['Titel'], |
| 173 | ['Untertitel'], |
| 174 | ['Veröffentlichungsdatum'], |
| 175 | ['Länge'], |
| 176 | ['Autor'], |
| 177 | ['Genre'], |
| 178 | ['corpusID'], |
| 179 | ['docID'], |
| 180 | ['textID'], |
| 181 | ]; |
| 182 | |
| 183 | it('should be initializable', function () { |
| 184 | /**var list = [ |
| 185 | ["Constituency"], |
| 186 | ["Lemma"], |
| 187 | ["Morphology"], |
| 188 | ["Part-of-Speech"], |
| 189 | ["Syntax"] |
| 190 | ]; |
| 191 | */ |
| 192 | |
| 193 | var menu = OwnContainerMenu.create(list,ExampleItemList); |
| 194 | // This is the same with and without additional container items! |
| 195 | expect(menu.dontHide).toBe(false); |
| 196 | menu._firstActive = true; |
| 197 | expect(menu.itemClass()).toEqual(OwnMenuItem); |
| 198 | expect(menu.element().nodeName).toEqual('UL'); |
| 199 | expect(menu.element().classList.contains('visible')).toBeFalsy(); |
| 200 | expect(menu.container().element().classList.contains('visible')).toBeFalsy(); |
| 201 | expect(menu.limit()).toEqual(8); |
| 202 | expect(menu._notItemElements).toEqual(3); |
| 203 | |
| 204 | menu.limit(9); |
| 205 | expect(menu.limit()).toEqual(9); |
| 206 | |
| 207 | menu.limit(8); |
| 208 | |
| 209 | // view |
| 210 | menu.show(); |
| 211 | expect(menu.element().classList.contains('visible')).toBeTruthy(); |
| 212 | expect(menu.container().element().classList.contains('visible')).toBeTruthy(); |
| 213 | |
| 214 | // First element in list |
| 215 | expect(menu.item(0).active()).toBe(true); |
| 216 | expect(menu.item(0).noMore()).toBe(true); |
| 217 | |
| 218 | // Middle element in list |
| 219 | expect(menu.item(2).active()).toBe(false); |
| 220 | expect(menu.item(2).noMore()).toBe(false); |
| 221 | |
| 222 | // Last element in list |
| 223 | expect(menu.item(menu.length() - 1).active()).toBe(false); |
| 224 | expect(menu.item(menu.length() - 1).noMore()).toBe(true); |
| 225 | |
| 226 | expect(menu.element().classList.contains('containermenu')).toBeTruthy(); |
| 227 | expect(menu.container()).toBeTruthy(); |
| 228 | expect(menu._container.element().nodeName).toEqual('UL'); // actually need new one for container! |
| 229 | expect(menu._prefix.element().nodeName).toEqual('SPAN'); |
| 230 | expect(menu._container._containerItemClass).toEqual(OwnContainerItemClass); |
| 231 | expect(menu._container.items.length).toEqual(3); |
| 232 | }); |
| 233 | |
| 234 | it('should have a reference to the menu', function () { |
| 235 | var menu = OwnContainerMenu.create(list,ExampleItemList); |
| 236 | expect(menu.item(0).menu()).toEqual(menu); |
| 237 | expect(menu.element().menu).toEqual(menu); |
| 238 | for (item of menu._container.items) { |
| 239 | expect(item._menu).toEqual(menu); |
| 240 | }; |
| 241 | }); |
| 242 | |
| 243 | |
| 244 | it('should be visible', function () { |
| 245 | var menu = OwnContainerMenu.create(list,ExampleItemList); |
| 246 | expect(menu.removeItems()).toBe(undefined); |
| 247 | menu.limit(3); |
| 248 | |
| 249 | expect(menu.show()).toBe(true); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 250 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 251 | expect(liElements[0].innerHTML).toEqual("Constituency"); |
| 252 | expect(liElements[1].innerHTML).toEqual("Lemma"); |
| 253 | expect(liElements[2].innerHTML).toEqual("Morphology"); |
| 254 | expect(liElements[3]).toBe(undefined); |
| 255 | |
| 256 | // Check boundaries |
| 257 | expect(liElements[0].classList.contains("no-more")).toBe(true); |
| 258 | expect(liElements[1].classList.contains("no-more")).toBe(false); |
| 259 | expect(liElements[2].classList.contains("no-more")).toBe(false); |
| 260 | |
| 261 | var items = menu.container().items; |
Leo Repp | 8453916 | 2021-10-25 12:06:07 +0200 | [diff] [blame] | 262 | expect(items[0].initContent().nodeValue).toEqual("CIText1 "); |
| 263 | expect(items[1].initContent().nodeValue).toEqual("CIText2 "); |
Leo Repp | 5799740 | 2021-08-18 16:37:52 +0200 | [diff] [blame] | 264 | expect(items[2].element().innerHTML).toEqual(""); //prefix! |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 265 | expect(items[3]).toBe(undefined); |
| 266 | }); |
| 267 | |
| 268 | it('should be filterable', function () { |
| 269 | var menu = OwnContainerMenu.create(list,ExampleItemList); |
| 270 | menu.limit(3); |
| 271 | expect(menu.prefix("o").show()).toBe(true); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 272 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 273 | expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("o"); |
| 274 | expect(liElements[0].innerHTML).toEqual("C<mark>o</mark>nstituency"); |
| 275 | expect(liElements[1].innerHTML).toEqual("M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy"); |
| 276 | expect(liElements[2].innerHTML).toEqual("Part-<mark>o</mark>f-Speech"); |
| 277 | expect(liElements[3]).toBe(undefined); |
| 278 | |
| 279 | // Check boundaries |
| 280 | expect(liElements[0].classList.contains("no-more")).toBe(true); |
| 281 | expect(liElements[1].classList.contains("no-more")).toBe(false); |
| 282 | expect(liElements[2].classList.contains("no-more")).toBe(true); |
| 283 | |
| 284 | menu.limit(2); |
| 285 | |
| 286 | expect(menu.prefix("o").show()).toBe(true); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 287 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 288 | expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("o"); |
| 289 | expect(liElements[0].innerHTML).toEqual("C<mark>o</mark>nstituency"); |
| 290 | expect(liElements[1].innerHTML).toEqual("M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy"); |
| 291 | |
| 292 | expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("o"); |
| 293 | expect(liElements[2]).toBe(undefined); |
| 294 | |
| 295 | // Check boundaries |
| 296 | expect(liElements[0].classList.contains("no-more")).toBe(true); |
| 297 | expect(liElements[1].classList.contains("no-more")).toBe(false); |
| 298 | expect(liElements[2]).toBe(undefined); |
| 299 | |
| 300 | expect(menu.prefix("e").show()).toBe(true); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 301 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 302 | expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("e"); |
| 303 | expect(liElements[0].innerHTML).toEqual("Constitu<mark>e</mark>ncy"); |
| 304 | expect(liElements[2]).toBe(undefined); |
| 305 | |
| 306 | menu.limit(5); |
| 307 | expect(menu.prefix("a").show()).toBe(true); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 308 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 309 | expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("a"); |
| 310 | expect(liElements[0].innerHTML).toEqual("Lemm<mark>a</mark>"); |
| 311 | expect(liElements[1].innerHTML).toEqual("P<mark>a</mark>rt-of-Speech"); |
| 312 | expect(liElements[2].innerHTML).toEqual("Synt<mark>a</mark>x"); |
| 313 | expect(liElements[3]).toBe(undefined); |
| 314 | |
| 315 | }); |
Leo Repp | 050a734 | 2021-10-25 11:05:32 +0200 | [diff] [blame] | 316 | |
| 317 | it('should switch to the containers prefix whenever the prefix filters the regular list to be empty', function () { |
| 318 | /**var list = [ |
| 319 | ["Constituency"], |
| 320 | ["Lemma"], |
| 321 | ["Morphology"], |
| 322 | ["Part-of-Speech"], |
| 323 | ["Syntax"] |
| 324 | ]; |
| 325 | */ |
| 326 | var menu = OwnContainerMenu.create(list,ExampleItemList); |
| 327 | menu.container().add("1"); |
| 328 | menu.show(); // Simulates Buttonpress 1 |
| 329 | // See function _keypress in containermenu.js (line 147) |
| 330 | expect(menu.liveItem()).toBeUndefined(); // no elements in list match "1" |
| 331 | expect(menu.container().active()).toBeTruthy(); //thus switch to container |
| 332 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
| 333 | expect(liElements).toEqual([]); |
| 334 | expect(menu.container().liveLength()).toEqual(3); //CI1 and 2, prefix |
| 335 | expect(menu._prefix.active()).toBeTruthy(); // HERE ONLY |
| 336 | // We want whichever container item was active before |
| 337 | // to stay active, default to prefix if none was. |
| 338 | |
| 339 | //simulate _keydown(...) see containermenu.js line 137 |
| 340 | menu.container().chop(); |
| 341 | menu.show(); |
| 342 | menu.prev(); |
| 343 | expect(menu._prefix.active()).toBeFalsy(); |
| 344 | expect(menu.container().item(1).active().toBeTruthy); // at location 1: CIItem 2 |
| 345 | expect(menu.liveLength()).toEqual(5); |
| 346 | |
| 347 | menu.container().add("1"); |
| 348 | menu.show(); // Simulates Buttonpress 1 |
| 349 | // See function _keypress in containermenu.js (line 147) |
| 350 | expect(menu.liveItem()).toBeUndefined(); // no elements in list match "1" |
| 351 | expect(menu.container().active()).toBeTruthy(); |
| 352 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
| 353 | expect(liElements).toEqual([]); |
| 354 | expect(menu.container().liveLength()).toEqual(3); //CI1 and 2, prefix |
| 355 | expect(menu.container().item(1).active().toBeTruthy); // at location 1: CIItem 2 |
| 356 | // We want whichever container item was active before |
| 357 | // to stay active, default to prefix if none was. |
| 358 | |
| 359 | }); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 360 | |
Leo Repp | c66268e | 2021-10-28 11:44:35 +0200 | [diff] [blame] | 361 | it('should allow removing an item from the container list', function () {/**var list = [ |
| 362 | ["Constituency"], |
| 363 | ["Lemma"], |
| 364 | ["Morphology"], |
| 365 | ["Part-of-Speech"], |
| 366 | ["Syntax"] |
| 367 | ]; |
| 368 | */ |
| 369 | var menu = OwnContainerMenu.create(list,ExampleItemList); |
| 370 | menu._firstActive = true; |
| 371 | menu.limit(3); |
| 372 | expect(menu.show()).toBe(true); |
| 373 | menu.next(); |
| 374 | menu.next(); |
| 375 | menu.next(); |
| 376 | menu.next(); |
| 377 | expect(menu.shownItem(2).active()).toBe(true); |
| 378 | expect(menu.container().item(0).active()).toBe(false); |
| 379 | expect(menu.container().item(1).active()).toBe(false); |
| 380 | expect(menu.container().item(2).active()).toBe(false); //prefix |
| 381 | expect(menu.container().item(2)).toEqual(menu._prefix); |
| 382 | expect(menu.container().length()).toBe(3); |
| 383 | menu.container().removeItemByIndex(0); |
| 384 | expect(menu.shownItem(2).active()).toBe(true); |
| 385 | expect(menu.container().item(0).active()).toBe(false); |
| 386 | expect(menu.container().item(1).active()).toBe(false); //prefix |
| 387 | expect(menu.container().item(1)).toEqual(menu._prefix); |
| 388 | expect(menu.container().length()).toBe(2); |
| 389 | menu.next(); |
| 390 | expect(menu.shownItem(2).active()).toBe(false); |
| 391 | expect(menu.container().item(0).active()).toBe(true); |
| 392 | expect(menu.container().item(1).active()).toBe(false); //prefix |
| 393 | expect(menu.container().item(1)).toEqual(menu._prefix); |
| 394 | expect(menu.container().length()).toBe(2); |
| 395 | menu.container().removeItemByIndex(0); |
| 396 | expect(menu.shownItem(2).active()).toBe(false); |
| 397 | expect(menu.shownItem(0).active()).toBe(true); |
| 398 | expect(menu.container().item(0).active()).toBe(false); //prefix //would be selected, if it were not "" |
| 399 | expect(menu.container().item(0)).toEqual(menu._prefix); |
| 400 | expect(menu.container().length()).toBe(1); |
| 401 | |
| 402 | |
| 403 | |
| 404 | }); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 405 | it('should be nextable', function () { |
| 406 | var menu = OwnContainerMenu.create(list); |
| 407 | menu._firstActive = true; |
| 408 | |
| 409 | // Show only 3 items |
| 410 | menu.limit(3); |
| 411 | expect(menu.show()).toBe(true); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 412 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 413 | expect(liElements[0].innerHTML).toEqual("Constituency"); |
| 414 | expect(menu.shownItem(0).active()).toBe(true); |
| 415 | expect(liElements[1].innerHTML).toEqual("Lemma"); |
| 416 | expect(menu.shownItem(1).active()).toBe(false); |
| 417 | expect(liElements[2].innerHTML).toEqual("Morphology"); |
| 418 | expect(menu.shownItem(2).active()).toBe(false); |
| 419 | expect(liElements[3]).toBe(undefined); |
| 420 | |
| 421 | // Activate next (1) |
| 422 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 423 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 424 | expect(liElements[0].innerHTML).toEqual("Constituency"); |
| 425 | expect(menu.shownItem(0).active()).toBe(false); |
| 426 | expect(liElements[1].innerHTML).toEqual("Lemma"); |
| 427 | expect(menu.shownItem(1).active()).toBe(true); |
| 428 | expect(liElements[2].innerHTML).toEqual("Morphology"); |
| 429 | expect(menu.shownItem(2).active()).toBe(false); |
| 430 | expect(liElements[3]).toBe(undefined); |
| 431 | |
| 432 | // Activate next (2) |
| 433 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 434 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 435 | expect(liElements[0].innerHTML).toEqual("Constituency"); |
| 436 | expect(menu.shownItem(0).active()).toBe(false); |
| 437 | expect(liElements[1].innerHTML).toEqual("Lemma"); |
| 438 | expect(menu.shownItem(1).active()).toBe(false); |
| 439 | expect(liElements[2].innerHTML).toEqual("Morphology"); |
| 440 | expect(menu.shownItem(2).active()).toBe(true); |
| 441 | expect(liElements[3]).toBe(undefined); |
| 442 | |
| 443 | // Activate next (3) |
| 444 | // scroll! |
| 445 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 446 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 447 | expect(liElements[0].innerHTML).toEqual("Lemma"); |
| 448 | expect(menu.shownItem(0).active()).toBe(false); |
| 449 | expect(liElements[1].innerHTML).toEqual("Morphology"); |
| 450 | expect(menu.shownItem(1).active()).toBe(false); |
| 451 | expect(liElements[2].innerHTML).toEqual("Part-of-Speech"); |
| 452 | expect(menu.shownItem(2).active()).toBe(true); |
| 453 | expect(liElements[3]).toBe(undefined); |
| 454 | |
| 455 | // Activate next (4) |
| 456 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 457 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 458 | expect(liElements[0].innerHTML).toEqual("Morphology"); |
| 459 | expect(menu.shownItem(0).active()).toBe(false); |
| 460 | expect(liElements[1].innerHTML).toEqual("Part-of-Speech"); |
| 461 | expect(menu.shownItem(1).active()).toBe(false); |
| 462 | expect(liElements[2].innerHTML).toEqual("Syntax"); |
| 463 | expect(menu.shownItem(2).active()).toBe(true); |
| 464 | expect(liElements[3]).toBe(undefined); |
| 465 | |
| 466 | // Activate next (5) - ROLL |
| 467 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 468 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 469 | expect(liElements[0].innerHTML).toEqual("Constituency"); |
| 470 | expect(menu.shownItem(0).active()).toBe(true); |
| 471 | expect(liElements[1].innerHTML).toEqual("Lemma"); |
| 472 | expect(menu.shownItem(1).active()).toBe(false); |
| 473 | expect(liElements[2].innerHTML).toEqual("Morphology"); |
| 474 | expect(menu.shownItem(2).active()).toBe(false); |
| 475 | expect(liElements[3]).toBe(undefined); |
| 476 | |
| 477 | // Active next (6) |
| 478 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 479 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 480 | expect(liElements[0].innerHTML).toEqual("Constituency"); |
| 481 | expect(menu.shownItem(0).active()).toBe(false); |
| 482 | expect(liElements[1].innerHTML).toEqual("Lemma"); |
| 483 | expect(menu.shownItem(1).active()).toBe(true); |
| 484 | expect(liElements[2].innerHTML).toEqual("Morphology"); |
| 485 | expect(menu.shownItem(2).active()).toBe(false); |
| 486 | expect(liElements[3]).toBe(undefined); |
| 487 | }); |
| 488 | |
| 489 | it('should be nextable when there are two containeritems', function () { |
| 490 | var menu = OwnContainerMenu.create(list,ExampleItemList); |
| 491 | menu._firstActive = true; |
| 492 | |
| 493 | // Show only 3 items |
| 494 | menu.limit(3); |
| 495 | expect(menu.show()).toBe(true); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 496 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 497 | expect(liElements[0].innerHTML).toEqual("Constituency"); |
| 498 | expect(menu.shownItem(0).active()).toBe(true); |
| 499 | expect(liElements[1].innerHTML).toEqual("Lemma"); |
| 500 | expect(menu.shownItem(1).active()).toBe(false); |
| 501 | expect(liElements[2].innerHTML).toEqual("Morphology"); |
| 502 | expect(menu.shownItem(2).active()).toBe(false); |
| 503 | expect(liElements[3]).toBe(undefined); |
| 504 | expect(menu.container().items[0].active()).toBe(false); |
| 505 | expect(menu.container().items[1].active()).toBe(false); |
| 506 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 507 | |
| 508 | // Activate next (1) |
| 509 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 510 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 511 | expect(liElements[0].innerHTML).toEqual("Constituency"); |
| 512 | expect(menu.shownItem(0).active()).toBe(false); |
| 513 | expect(liElements[1].innerHTML).toEqual("Lemma"); |
| 514 | expect(menu.shownItem(1).active()).toBe(true); |
| 515 | expect(liElements[2].innerHTML).toEqual("Morphology"); |
| 516 | expect(menu.shownItem(2).active()).toBe(false); |
| 517 | expect(liElements[3]).toBe(undefined); |
| 518 | expect(menu.container().items[0].active()).toBe(false); |
| 519 | expect(menu.container().items[1].active()).toBe(false); |
| 520 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 521 | |
| 522 | // Activate next (2) |
| 523 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 524 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 525 | expect(liElements[0].innerHTML).toEqual("Constituency"); |
| 526 | expect(menu.shownItem(0).active()).toBe(false); |
| 527 | expect(liElements[1].innerHTML).toEqual("Lemma"); |
| 528 | expect(menu.shownItem(1).active()).toBe(false); |
| 529 | expect(liElements[2].innerHTML).toEqual("Morphology"); |
| 530 | expect(menu.shownItem(2).active()).toBe(true); |
| 531 | expect(liElements[3]).toBe(undefined); |
| 532 | expect(menu.container().items[0].active()).toBe(false); |
| 533 | expect(menu.container().items[1].active()).toBe(false); |
| 534 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 535 | |
| 536 | // Activate next (3) |
| 537 | // scroll! |
| 538 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 539 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 540 | expect(liElements[0].innerHTML).toEqual("Lemma"); |
| 541 | expect(menu.shownItem(0).active()).toBe(false); |
| 542 | expect(liElements[1].innerHTML).toEqual("Morphology"); |
| 543 | expect(menu.shownItem(1).active()).toBe(false); |
| 544 | expect(liElements[2].innerHTML).toEqual("Part-of-Speech"); |
| 545 | expect(menu.shownItem(2).active()).toBe(true); |
| 546 | expect(liElements[3]).toBe(undefined); |
| 547 | expect(menu.container().items[0].active()).toBe(false); |
| 548 | expect(menu.container().items[1].active()).toBe(false); |
| 549 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 550 | |
| 551 | // Activate next (4) |
| 552 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 553 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 554 | expect(liElements[0].innerHTML).toEqual("Morphology"); |
| 555 | expect(menu.shownItem(0).active()).toBe(false); |
| 556 | expect(liElements[1].innerHTML).toEqual("Part-of-Speech"); |
| 557 | expect(menu.shownItem(1).active()).toBe(false); |
| 558 | expect(liElements[2].innerHTML).toEqual("Syntax"); |
| 559 | expect(menu.shownItem(2).active()).toBe(true); |
| 560 | expect(liElements[3]).toBe(undefined); |
| 561 | expect(menu.container().items[0].active()).toBe(false); |
| 562 | expect(menu.container().items[1].active()).toBe(false); |
| 563 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 564 | |
| 565 | // Activate next (4.1) - Jump to container part |
| 566 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 567 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 568 | expect(liElements[0].innerHTML).toEqual("Morphology"); |
| 569 | expect(menu.shownItem(0).active()).toBe(false); |
| 570 | expect(liElements[1].innerHTML).toEqual("Part-of-Speech"); |
| 571 | expect(menu.shownItem(1).active()).toBe(false); |
| 572 | expect(liElements[2].innerHTML).toEqual("Syntax"); |
| 573 | expect(menu.shownItem(2).active()).toBe(false); |
| 574 | expect(liElements[3]).toBe(undefined); |
| 575 | expect(menu.container().items[0].active()).toBe(true); |
| 576 | expect(menu.container().items[1].active()).toBe(false); |
| 577 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 578 | |
| 579 | // Activate next (4.2) |
| 580 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 581 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 582 | expect(liElements[0].innerHTML).toEqual("Morphology"); |
| 583 | expect(menu.shownItem(0).active()).toBe(false); |
| 584 | expect(liElements[1].innerHTML).toEqual("Part-of-Speech"); |
| 585 | expect(menu.shownItem(1).active()).toBe(false); |
| 586 | expect(liElements[2].innerHTML).toEqual("Syntax"); |
| 587 | expect(menu.shownItem(2).active()).toBe(false); |
| 588 | expect(liElements[3]).toBe(undefined); |
| 589 | expect(menu.container().items[0].active()).toBe(false); |
| 590 | expect(menu.container().items[1].active()).toBe(true); |
| 591 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 592 | |
| 593 | /** Prefix is not set |
| 594 | // Activate next (4.3) |
| 595 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 596 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 597 | expect(liElements[0].innerHTML).toEqual("Morphology"); |
| 598 | expect(menu.shownItem(0).active()).toBe(false); |
| 599 | expect(liElements[1].innerHTML).toEqual("Part-of-Speech"); |
| 600 | expect(menu.shownItem(1).active()).toBe(false); |
| 601 | expect(liElements[2].innerHTML).toEqual("Syntax"); |
| 602 | expect(menu.shownItem(2).active()).toBe(true); |
| 603 | expect(liElements[3]).toBe(undefined); |
| 604 | expect(menu.container().items[0].active()).toBe(false); |
| 605 | expect(menu.container().items[1].active()).toBe(false); |
| 606 | expect(menu.container().items[2].active()).toBe(true); //prefix |
| 607 | */ |
| 608 | |
| 609 | // Activate next (5) - ROLL |
| 610 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 611 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 612 | expect(liElements[0].innerHTML).toEqual("Constituency"); |
| 613 | expect(menu.shownItem(0).active()).toBe(true); |
| 614 | expect(liElements[1].innerHTML).toEqual("Lemma"); |
| 615 | expect(menu.shownItem(1).active()).toBe(false); |
| 616 | expect(liElements[2].innerHTML).toEqual("Morphology"); |
| 617 | expect(menu.shownItem(2).active()).toBe(false); |
| 618 | expect(liElements[3]).toBe(undefined); |
| 619 | expect(menu.container().items[0].active()).toBe(false); |
| 620 | expect(menu.container().items[1].active()).toBe(false); |
| 621 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 622 | |
| 623 | // Active next (6) |
| 624 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 625 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 626 | expect(liElements[0].innerHTML).toEqual("Constituency"); |
| 627 | expect(menu.shownItem(0).active()).toBe(false); |
| 628 | expect(liElements[1].innerHTML).toEqual("Lemma"); |
| 629 | expect(menu.shownItem(1).active()).toBe(true); |
| 630 | expect(liElements[2].innerHTML).toEqual("Morphology"); |
| 631 | expect(menu.shownItem(2).active()).toBe(false); |
| 632 | expect(liElements[3]).toBe(undefined); |
| 633 | expect(menu.container().items[0].active()).toBe(false); |
| 634 | expect(menu.container().items[1].active()).toBe(false); |
| 635 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 636 | }); |
| 637 | |
| 638 | it('should be nextable without active field', function () { |
| 639 | var menu = OwnContainerMenu.create(list,ExampleItemList); |
| 640 | menu.limit(3); |
| 641 | expect(menu.show()).toBe(true); |
| 642 | menu.next(); |
| 643 | expect(menu.shownItem(0).active()).toEqual(true); |
| 644 | }); |
| 645 | |
| 646 | |
| 647 | it('should be prevable', function () { |
| 648 | var menu = OwnContainerMenu.create(list); |
| 649 | menu._firstActive = true; |
| 650 | menu.limit(3); |
| 651 | expect(menu.show()).toBe(true); |
| 652 | |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 653 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 654 | expect(liElements[0].innerHTML).toEqual("Constituency"); |
| 655 | expect(menu.shownItem(0).active()).toBe(true); |
| 656 | expect(liElements[1].innerHTML).toEqual("Lemma"); |
| 657 | expect(menu.shownItem(1).active()).toBe(false); |
| 658 | expect(liElements[2].innerHTML).toEqual("Morphology"); |
| 659 | expect(menu.shownItem(2).active()).toBe(false); |
| 660 | expect(liElements[3]).toBe(undefined); |
| 661 | |
| 662 | // Activate prev (1) - roll to bottom |
| 663 | menu.prev(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 664 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 665 | expect(liElements[0].innerHTML).toEqual("Morphology"); |
| 666 | expect(menu.shownItem(0).active()).toBe(false); |
| 667 | expect(liElements[1].innerHTML).toEqual("Part-of-Speech"); |
| 668 | expect(menu.shownItem(1).active()).toBe(false); |
| 669 | expect(liElements[2].innerHTML).toEqual("Syntax"); |
| 670 | expect(menu.shownItem(2).active()).toBe(true); |
| 671 | expect(liElements[3]).toBe(undefined); |
| 672 | |
| 673 | // Activate prev (2) |
| 674 | menu.prev(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 675 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 676 | expect(liElements[0].innerHTML).toEqual("Morphology"); |
| 677 | expect(menu.shownItem(0).active()).toBe(false); |
| 678 | expect(liElements[1].innerHTML).toEqual("Part-of-Speech"); |
| 679 | expect(menu.shownItem(1).active()).toBe(true); |
| 680 | expect(liElements[2].innerHTML).toEqual("Syntax"); |
| 681 | expect(menu.shownItem(2).active()).toBe(false); |
| 682 | expect(liElements[3]).toBe(undefined); |
| 683 | |
| 684 | // Activate prev (3) |
| 685 | menu.prev(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 686 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 687 | expect(liElements[0].innerHTML).toEqual("Morphology"); |
| 688 | expect(menu.shownItem(0).active()).toBe(true); |
| 689 | expect(liElements[1].innerHTML).toEqual("Part-of-Speech"); |
| 690 | expect(menu.shownItem(1).active()).toBe(false); |
| 691 | expect(liElements[2].innerHTML).toEqual("Syntax"); |
| 692 | expect(menu.shownItem(2).active()).toBe(false); |
| 693 | expect(liElements[3]).toBe(undefined); |
| 694 | |
| 695 | // Activate prev (4) |
| 696 | menu.prev(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 697 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 698 | expect(liElements[0].innerHTML).toEqual("Lemma"); |
| 699 | expect(menu.shownItem(0).active()).toBe(true); |
| 700 | expect(liElements[1].innerHTML).toEqual("Morphology"); |
| 701 | expect(menu.shownItem(1).active()).toBe(false); |
| 702 | expect(liElements[2].innerHTML).toEqual("Part-of-Speech"); |
| 703 | expect(menu.shownItem(2).active()).toBe(false); |
| 704 | expect(liElements[3]).toBe(undefined); |
| 705 | |
| 706 | // Activate prev (5) |
| 707 | menu.prev(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 708 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 709 | expect(liElements[0].innerHTML).toEqual("Constituency"); |
| 710 | expect(menu.shownItem(0).active()).toBe(true); |
| 711 | expect(liElements[1].innerHTML).toEqual("Lemma"); |
| 712 | expect(menu.shownItem(1).active()).toBe(false); |
| 713 | expect(liElements[2].innerHTML).toEqual("Morphology"); |
| 714 | expect(menu.shownItem(2).active()).toBe(false); |
| 715 | expect(liElements[3]).toBe(undefined); |
| 716 | |
| 717 | // Activate next (1) |
| 718 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 719 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 720 | expect(liElements[0].innerHTML).toEqual("Constituency"); |
| 721 | expect(menu.shownItem(0).active()).toBe(false); |
| 722 | expect(liElements[1].innerHTML).toEqual("Lemma"); |
| 723 | expect(menu.shownItem(1).active()).toBe(true); |
| 724 | expect(liElements[2].innerHTML).toEqual("Morphology"); |
| 725 | expect(menu.shownItem(2).active()).toBe(false); |
| 726 | expect(liElements[3]).toBe(undefined); |
| 727 | |
| 728 | // Activate prev (6) |
| 729 | menu.prev(); |
| 730 | |
| 731 | // Activate prev (7) |
| 732 | menu.prev(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 733 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 734 | expect(liElements[0].innerHTML).toEqual("Morphology"); |
| 735 | expect(menu.shownItem(0).active()).toBe(false); |
| 736 | expect(liElements[1].innerHTML).toEqual("Part-of-Speech"); |
| 737 | expect(menu.shownItem(1).active()).toBe(false); |
| 738 | expect(liElements[2].innerHTML).toEqual("Syntax"); |
| 739 | expect(menu.shownItem(2).active()).toBe(true); |
| 740 | expect(liElements[3]).toBe(undefined); |
| 741 | }); |
| 742 | |
| 743 | it('should be prevable with containerItems', function () { |
| 744 | var menu = OwnContainerMenu.create(list,ExampleItemList); |
| 745 | menu._firstActive = true; |
| 746 | menu.limit(3); |
| 747 | expect(menu.show()).toBe(true); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 748 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 749 | expect(liElements[0].innerHTML).toEqual("Constituency"); |
| 750 | expect(menu.shownItem(0).active()).toBe(true); |
| 751 | expect(liElements[1].innerHTML).toEqual("Lemma"); |
| 752 | expect(menu.shownItem(1).active()).toBe(false); |
| 753 | expect(liElements[2].innerHTML).toEqual("Morphology"); |
| 754 | expect(menu.shownItem(2).active()).toBe(false); |
| 755 | expect(liElements[3]).toBe(undefined); |
| 756 | expect(menu.container().items[0].active()).toBe(false); |
| 757 | expect(menu.container().items[1].active()).toBe(false); |
| 758 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 759 | |
| 760 | // Activate prev (1) - roll to bottom - base items stay, now container |
| 761 | menu.prev(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 762 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 763 | expect(liElements[0].innerHTML).toEqual("Constituency"); |
| 764 | expect(menu.shownItem(0).active()).toBe(false); |
| 765 | expect(liElements[1].innerHTML).toEqual("Lemma"); |
| 766 | expect(menu.shownItem(1).active()).toBe(false); |
| 767 | expect(liElements[2].innerHTML).toEqual("Morphology"); |
| 768 | expect(menu.shownItem(2).active()).toBe(false); |
| 769 | expect(liElements[3]).toBe(undefined); |
| 770 | expect(menu.container().items[0].active()).toBe(false); |
| 771 | expect(menu.container().items[1].active()).toBe(true); |
| 772 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 773 | |
| 774 | // Activate prev(2) - next container item |
| 775 | menu.prev(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 776 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 777 | expect(liElements[0].innerHTML).toEqual("Constituency"); |
| 778 | expect(menu.shownItem(0).active()).toBe(false); |
| 779 | expect(liElements[1].innerHTML).toEqual("Lemma"); |
| 780 | expect(menu.shownItem(1).active()).toBe(false); |
| 781 | expect(liElements[2].innerHTML).toEqual("Morphology"); |
| 782 | expect(menu.shownItem(2).active()).toBe(false); |
| 783 | expect(liElements[3]).toBe(undefined); |
| 784 | expect(menu.container().items[0].active()).toBe(true); |
| 785 | expect(menu.container().items[1].active()).toBe(false); |
| 786 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 787 | |
| 788 | // Activate prev (3) - roll to bottom of normal list |
| 789 | menu.prev(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 790 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 791 | expect(liElements[0].innerHTML).toEqual("Morphology"); |
| 792 | expect(menu.shownItem(0).active()).toBe(false); |
| 793 | expect(liElements[1].innerHTML).toEqual("Part-of-Speech"); |
| 794 | expect(menu.shownItem(1).active()).toBe(false); |
| 795 | expect(liElements[2].innerHTML).toEqual("Syntax"); |
| 796 | expect(menu.shownItem(2).active()).toBe(true); |
| 797 | expect(liElements[3]).toBe(undefined); |
| 798 | expect(menu.container().items[0].active()).toBe(false); |
| 799 | expect(menu.container().items[1].active()).toBe(false); |
| 800 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 801 | |
| 802 | // Activate prev (4) |
| 803 | menu.prev(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 804 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 805 | expect(liElements[0].innerHTML).toEqual("Morphology"); |
| 806 | expect(menu.shownItem(0).active()).toBe(false); |
| 807 | expect(liElements[1].innerHTML).toEqual("Part-of-Speech"); |
| 808 | expect(menu.shownItem(1).active()).toBe(true); |
| 809 | expect(liElements[2].innerHTML).toEqual("Syntax"); |
| 810 | expect(menu.shownItem(2).active()).toBe(false); |
| 811 | expect(liElements[3]).toBe(undefined); |
| 812 | expect(menu.container().items[0].active()).toBe(false); |
| 813 | expect(menu.container().items[1].active()).toBe(false); |
| 814 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 815 | |
| 816 | // Activate prev (5) |
| 817 | menu.prev(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 818 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 819 | expect(liElements[0].innerHTML).toEqual("Morphology"); |
| 820 | expect(menu.shownItem(0).active()).toBe(true); |
| 821 | expect(liElements[1].innerHTML).toEqual("Part-of-Speech"); |
| 822 | expect(menu.shownItem(1).active()).toBe(false); |
| 823 | expect(liElements[2].innerHTML).toEqual("Syntax"); |
| 824 | expect(menu.shownItem(2).active()).toBe(false); |
| 825 | expect(liElements[3]).toBe(undefined); |
| 826 | expect(menu.container().items[0].active()).toBe(false); |
| 827 | expect(menu.container().items[1].active()).toBe(false); |
| 828 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 829 | |
| 830 | // Activate prev (6) |
| 831 | menu.prev(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 832 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 833 | expect(liElements[0].innerHTML).toEqual("Lemma"); |
| 834 | expect(menu.shownItem(0).active()).toBe(true); |
| 835 | expect(liElements[1].innerHTML).toEqual("Morphology"); |
| 836 | expect(menu.shownItem(1).active()).toBe(false); |
| 837 | expect(liElements[2].innerHTML).toEqual("Part-of-Speech"); |
| 838 | expect(menu.shownItem(2).active()).toBe(false); |
| 839 | expect(liElements[3]).toBe(undefined); |
| 840 | expect(menu.container().items[0].active()).toBe(false); |
| 841 | expect(menu.container().items[1].active()).toBe(false); |
| 842 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 843 | |
| 844 | // Activate prev (7) |
| 845 | menu.prev(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 846 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 847 | expect(liElements[0].innerHTML).toEqual("Constituency"); |
| 848 | expect(menu.shownItem(0).active()).toBe(true); |
| 849 | expect(liElements[1].innerHTML).toEqual("Lemma"); |
| 850 | expect(menu.shownItem(1).active()).toBe(false); |
| 851 | expect(liElements[2].innerHTML).toEqual("Morphology"); |
| 852 | expect(menu.shownItem(2).active()).toBe(false); |
| 853 | expect(liElements[3]).toBe(undefined); |
| 854 | expect(menu.container().items[0].active()).toBe(false); |
| 855 | expect(menu.container().items[1].active()).toBe(false); |
| 856 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 857 | |
| 858 | // Activate next (8) |
| 859 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 860 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 861 | expect(liElements[0].innerHTML).toEqual("Constituency"); |
| 862 | expect(menu.shownItem(0).active()).toBe(false); |
| 863 | expect(liElements[1].innerHTML).toEqual("Lemma"); |
| 864 | expect(menu.shownItem(1).active()).toBe(true); |
| 865 | expect(liElements[2].innerHTML).toEqual("Morphology"); |
| 866 | expect(menu.shownItem(2).active()).toBe(false); |
| 867 | expect(liElements[3]).toBe(undefined); |
| 868 | expect(menu.container().items[0].active()).toBe(false); |
| 869 | expect(menu.container().items[1].active()).toBe(false); |
| 870 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 871 | |
| 872 | // Activate prev (9) |
| 873 | menu.prev(); |
| 874 | menu.prev(); |
| 875 | menu.prev(); |
| 876 | |
| 877 | // Activate prev (10) |
| 878 | menu.prev(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 879 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 880 | expect(liElements[0].innerHTML).toEqual("Morphology"); |
| 881 | expect(menu.shownItem(0).active()).toBe(false); |
| 882 | expect(liElements[1].innerHTML).toEqual("Part-of-Speech"); |
| 883 | expect(menu.shownItem(1).active()).toBe(false); |
| 884 | expect(liElements[2].innerHTML).toEqual("Syntax"); |
| 885 | expect(menu.shownItem(2).active()).toBe(true); |
| 886 | expect(liElements[3]).toBe(undefined); |
| 887 | expect(menu.container().items[0].active()).toBe(false); |
| 888 | expect(menu.container().items[1].active()).toBe(false); |
| 889 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 890 | }); |
| 891 | |
| 892 | it('should be prevable without active field', function () { |
| 893 | var menu = OwnContainerMenu.create(list); |
| 894 | menu.limit(3); |
| 895 | expect(menu.show()).toBe(true); |
| 896 | menu.prev(); |
| 897 | expect(menu.shownItem(2).active()).toEqual(true); |
| 898 | expect(menu.shownItem(2).lcField()).toEqual(' syntax'); |
| 899 | }); |
| 900 | |
| 901 | it('should be navigatable and filterable (prefix = "o")', function () { |
| 902 | var menu = OwnContainerMenu.create(list); |
| 903 | menu._firstActive = true; |
| 904 | menu.limit(2); |
| 905 | |
| 906 | expect(menu.prefix("o").show()).toBe(true); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 907 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 908 | expect(liElements[0].innerHTML).toEqual("C<mark>o</mark>nstituency"); |
| 909 | expect(menu.shownItem(0).active()).toBe(true); |
| 910 | expect(liElements[1].innerHTML).toEqual("M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy"); |
| 911 | expect(menu.shownItem(1).active()).toBe(false); |
| 912 | expect(menu.shownItem(2)).toBe(undefined); |
| 913 | |
| 914 | // Next (1) |
| 915 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 916 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 917 | expect(liElements[0].innerHTML).toEqual("C<mark>o</mark>nstituency"); |
| 918 | expect(menu.shownItem(0).active()).toBe(false); |
| 919 | expect(liElements[1].innerHTML).toEqual("M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy"); |
| 920 | expect(menu.shownItem(1).active()).toBe(true); |
| 921 | expect(menu.shownItem(2)).toBe(undefined); |
| 922 | |
| 923 | // Next (2) |
| 924 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 925 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 926 | expect(liElements[0].innerHTML).toEqual("M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy"); |
| 927 | expect(menu.shownItem(0).active()).toBe(false); |
| 928 | expect(liElements[1].innerHTML).toEqual("Part-<mark>o</mark>f-Speech"); |
| 929 | expect(menu.shownItem(1).active()).toBe(true); |
| 930 | expect(menu.shownItem(2)).toBe(undefined); |
| 931 | |
| 932 | // Next (3) - to prefix |
| 933 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 934 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 935 | expect(liElements[0].innerHTML).toEqual("M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy"); |
| 936 | expect(menu.shownItem(0).active()).toBe(false); |
| 937 | expect(liElements[1].innerHTML).toEqual("Part-<mark>o</mark>f-Speech"); |
| 938 | expect(menu.shownItem(1).active()).toBe(false); |
| 939 | expect(menu.shownItem(2)).toBe(undefined); |
| 940 | |
| 941 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 942 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 943 | expect(liElements[0].innerHTML).toEqual("C<mark>o</mark>nstituency"); |
| 944 | expect(menu.shownItem(0).active()).toBe(true); |
| 945 | expect(liElements[1].innerHTML).toEqual("M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy"); |
| 946 | expect(menu.shownItem(1).active()).toBe(false); |
| 947 | expect(menu.shownItem(2)).toBe(undefined); |
| 948 | }); |
| 949 | |
| 950 | it('should be navigatable and filterable (prefix = "o") using containerItems', function () { |
| 951 | var menu = OwnContainerMenu.create(list,ExampleItemList); |
| 952 | menu._firstActive = true; |
| 953 | menu.limit(2); |
| 954 | |
| 955 | expect(menu.prefix("o").show()).toBe(true); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 956 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 957 | expect(liElements[0].innerHTML).toEqual("C<mark>o</mark>nstituency"); |
| 958 | expect(menu.shownItem(0).active()).toBe(true); |
| 959 | expect(liElements[1].innerHTML).toEqual("M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy"); |
| 960 | expect(menu.shownItem(1).active()).toBe(false); |
| 961 | expect(menu.shownItem(2)).toBe(undefined); |
| 962 | expect(menu.container().items[0].active()).toBe(false); |
| 963 | expect(menu.container().items[1].active()).toBe(false); |
| 964 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 965 | |
| 966 | // Next (1) |
| 967 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 968 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 969 | expect(liElements[0].innerHTML).toEqual("C<mark>o</mark>nstituency"); |
| 970 | expect(menu.shownItem(0).active()).toBe(false); |
| 971 | expect(liElements[1].innerHTML).toEqual("M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy"); |
| 972 | expect(menu.shownItem(1).active()).toBe(true); |
| 973 | expect(menu.shownItem(2)).toBe(undefined); |
| 974 | expect(menu.container().items[0].active()).toBe(false); |
| 975 | expect(menu.container().items[1].active()).toBe(false); |
| 976 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 977 | |
| 978 | // Next (2) |
| 979 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 980 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 981 | expect(liElements[0].innerHTML).toEqual("M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy"); |
| 982 | expect(menu.shownItem(0).active()).toBe(false); |
| 983 | expect(liElements[1].innerHTML).toEqual("Part-<mark>o</mark>f-Speech"); |
| 984 | expect(menu.shownItem(1).active()).toBe(true); |
| 985 | expect(menu.shownItem(2)).toBe(undefined); |
| 986 | expect(menu.container().items[0].active()).toBe(false); |
| 987 | expect(menu.container().items[1].active()).toBe(false); |
| 988 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 989 | |
| 990 | // Next (3) - to first container Item |
| 991 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 992 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 993 | expect(liElements[0].innerHTML).toEqual("M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy"); |
| 994 | expect(menu.shownItem(0).active()).toBe(false); |
| 995 | expect(liElements[1].innerHTML).toEqual("Part-<mark>o</mark>f-Speech"); |
| 996 | expect(menu.shownItem(1).active()).toBe(false); |
| 997 | expect(menu.shownItem(2)).toBe(undefined); |
| 998 | expect(menu.container().items[0].active()).toBe(true); |
| 999 | expect(menu.container().items[1].active()).toBe(false); |
| 1000 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1001 | |
| 1002 | // Next (4) - to second container Item |
| 1003 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1004 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1005 | expect(liElements[0].innerHTML).toEqual("M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy"); |
| 1006 | expect(menu.shownItem(0).active()).toBe(false); |
| 1007 | expect(liElements[1].innerHTML).toEqual("Part-<mark>o</mark>f-Speech"); |
| 1008 | expect(menu.shownItem(1).active()).toBe(false); |
| 1009 | expect(menu.shownItem(2)).toBe(undefined); |
| 1010 | expect(menu.container().items[0].active()).toBe(false); |
| 1011 | expect(menu.container().items[1].active()).toBe(true); |
| 1012 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1013 | |
| 1014 | // Next (5) - to prefix |
| 1015 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1016 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1017 | expect(liElements[0].innerHTML).toEqual("M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy"); |
| 1018 | expect(menu.shownItem(0).active()).toBe(false); |
| 1019 | expect(liElements[1].innerHTML).toEqual("Part-<mark>o</mark>f-Speech"); |
| 1020 | expect(menu.shownItem(1).active()).toBe(false); |
| 1021 | expect(menu.shownItem(2)).toBe(undefined); |
| 1022 | expect(menu.container().items[0].active()).toBe(false); |
| 1023 | expect(menu.container().items[1].active()).toBe(false); |
| 1024 | expect(menu.container().items[2].active()).toBe(true); //prefix |
| 1025 | |
| 1026 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1027 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1028 | expect(liElements[0].innerHTML).toEqual("C<mark>o</mark>nstituency"); |
| 1029 | expect(menu.shownItem(0).active()).toBe(true); |
| 1030 | expect(liElements[1].innerHTML).toEqual("M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy"); |
| 1031 | expect(menu.shownItem(1).active()).toBe(false); |
| 1032 | expect(menu.shownItem(2)).toBe(undefined); |
| 1033 | expect(menu.container().items[0].active()).toBe(false); |
| 1034 | expect(menu.container().items[1].active()).toBe(false); |
| 1035 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1036 | }); |
| 1037 | |
| 1038 | it('should be navigatable and filterable (prefix = "ex", "e") with containerItems', function () { |
| 1039 | var menu = OwnContainerMenu.create(listWithEX,ExampleItemList); |
| 1040 | menu._firstActive = true; |
| 1041 | menu.limit(3); |
| 1042 | |
| 1043 | expect(menu.prefix("ex").show()).toBe(true); |
| 1044 | expect(menu.prefix()).toEqual('ex'); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1045 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1046 | expect(liElements[0].innerHTML).toEqual("<mark>ex</mark>ample 1 Constituency"); |
| 1047 | expect(menu.shownItem(0).active()).toBe(true); |
| 1048 | expect(liElements[1].innerHTML).toEqual("<mark>ex</mark>ample 2 Morphology"); |
| 1049 | expect(menu.shownItem(1).active()).toBe(false); |
| 1050 | expect(menu.shownItem(3)).toBe(undefined); |
| 1051 | expect(menu.container().items[0].active()).toBe(false); |
| 1052 | expect(menu.container().items[1].active()).toBe(false); |
| 1053 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1054 | |
| 1055 | // Next (1) |
| 1056 | menu.next(); |
| 1057 | expect(menu.prefix()).toEqual('ex'); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1058 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1059 | expect(liElements[0].innerHTML).toEqual("<mark>ex</mark>ample 1 Constituency"); |
| 1060 | expect(menu.shownItem(0).active()).toBe(false); |
| 1061 | expect(liElements[1].innerHTML).toEqual("<mark>ex</mark>ample 2 Morphology"); |
| 1062 | expect(menu.shownItem(1).active()).toBe(true); |
| 1063 | expect(menu.shownItem(3)).toBe(undefined); |
| 1064 | expect(menu.container().items[0].active()).toBe(false); |
| 1065 | expect(menu.container().items[1].active()).toBe(false); |
| 1066 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1067 | |
| 1068 | // Next (2) |
| 1069 | menu.next(); |
| 1070 | expect(menu.prefix()).toEqual('ex'); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1071 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1072 | expect(liElements[0].innerHTML).toEqual("<mark>ex</mark>ample 1 Constituency"); |
| 1073 | expect(menu.shownItem(0).active()).toBe(false); |
| 1074 | expect(liElements[1].innerHTML).toEqual("<mark>ex</mark>ample 2 Morphology"); |
| 1075 | expect(menu.shownItem(1).active()).toBe(false); |
| 1076 | expect(menu.shownItem(3)).toBe(undefined); |
| 1077 | expect(menu.container().items[0].active()).toBe(true); |
| 1078 | expect(menu.container().items[1].active()).toBe(false); |
| 1079 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1080 | |
| 1081 | //Roll to Prefix |
| 1082 | menu.next(); |
| 1083 | menu.next(); |
| 1084 | expect(menu.prefix()).toEqual('ex'); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1085 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1086 | expect(liElements[0].innerHTML).toEqual("<mark>ex</mark>ample 1 Constituency"); |
| 1087 | expect(menu.shownItem(0).active()).toBe(false); |
| 1088 | expect(liElements[1].innerHTML).toEqual("<mark>ex</mark>ample 2 Morphology"); |
| 1089 | expect(menu.shownItem(1).active()).toBe(false); |
| 1090 | expect(menu.shownItem(3)).toBe(undefined); |
| 1091 | expect(menu.container().items[0].active()).toBe(false); |
| 1092 | expect(menu.container().items[1].active()).toBe(false); |
| 1093 | expect(menu.container().items[2].active()).toBe(true); //prefix |
| 1094 | |
| 1095 | // Reset limit |
| 1096 | menu.limit(5); |
| 1097 | |
| 1098 | // Change show |
| 1099 | expect(menu.prefix("e").show()).toBe(true); |
| 1100 | expect(menu._prefix.active()).toBe(false); |
| 1101 | expect(menu.prefix()).toEqual('e'); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1102 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1103 | expect(liElements[0].innerHTML).toEqual("<mark>e</mark>xampl<mark>e</mark> 1 Constitu<mark>e</mark>ncy"); |
| 1104 | expect(menu.shownItem(0).active()).toBe(true); |
| 1105 | expect(liElements[1].innerHTML).toEqual("<mark>e</mark>xampl<mark>e</mark> 2 Morphology"); |
| 1106 | expect(menu.shownItem(1).active()).toBe(false); |
| 1107 | expect(menu.shownItem(3)).toBe(undefined); |
| 1108 | expect(menu.container().items[0].active()).toBe(false); |
| 1109 | expect(menu.container().items[1].active()).toBe(false); |
| 1110 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1111 | |
| 1112 | // Next (1) |
| 1113 | menu.next(); |
| 1114 | expect(menu._prefix.active()).toBe(false); |
| 1115 | expect(menu.prefix()).toEqual('e'); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1116 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1117 | expect(liElements[0].innerHTML).toEqual("<mark>e</mark>xampl<mark>e</mark> 1 Constitu<mark>e</mark>ncy"); |
| 1118 | expect(menu.shownItem(0).active()).toBe(false); |
| 1119 | expect(liElements[1].innerHTML).toEqual("<mark>e</mark>xampl<mark>e</mark> 2 Morphology"); |
| 1120 | expect(menu.shownItem(1).active()).toBe(true); |
| 1121 | expect(menu.shownItem(3)).toBe(undefined); |
| 1122 | expect(menu.container().items[0].active()).toBe(false); |
| 1123 | expect(menu.container().items[1].active()).toBe(false); |
| 1124 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1125 | |
| 1126 | // Next (2) |
| 1127 | menu.next(); |
| 1128 | expect(menu._prefix.active()).toBe(false); |
| 1129 | expect(menu.prefix()).toEqual('e'); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1130 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1131 | expect(liElements[0].innerHTML).toEqual("<mark>e</mark>xampl<mark>e</mark> 1 Constitu<mark>e</mark>ncy"); |
| 1132 | expect(menu.shownItem(0).active()).toBe(false); |
| 1133 | expect(liElements[1].innerHTML).toEqual("<mark>e</mark>xampl<mark>e</mark> 2 Morphology"); |
| 1134 | expect(menu.shownItem(1).active()).toBe(false); |
| 1135 | expect(menu.shownItem(3)).toBe(undefined); |
| 1136 | expect(menu.container().items[0].active()).toBe(true); |
| 1137 | expect(menu.container().items[1].active()).toBe(false); |
| 1138 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1139 | |
| 1140 | |
| 1141 | // Next (3) |
| 1142 | menu.next(); |
| 1143 | menu.next(); |
| 1144 | expect(menu._prefix.active()).toBe(true); |
| 1145 | expect(menu.prefix()).toEqual('e'); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1146 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1147 | expect(liElements[0].innerHTML).toEqual("<mark>e</mark>xampl<mark>e</mark> 1 Constitu<mark>e</mark>ncy"); |
| 1148 | expect(menu.shownItem(0).active()).toBe(false); |
| 1149 | expect(liElements[1].innerHTML).toEqual("<mark>e</mark>xampl<mark>e</mark> 2 Morphology"); |
| 1150 | expect(menu.shownItem(1).active()).toBe(false); |
| 1151 | expect(menu.shownItem(3)).toBe(undefined); |
| 1152 | expect(menu.container().items[0].active()).toBe(false); |
| 1153 | expect(menu.container().items[1].active()).toBe(false); |
| 1154 | expect(menu.container().items[2].active()).toBe(true); //prefix |
| 1155 | }); |
| 1156 | |
| 1157 | |
| 1158 | it('should be filterable (multiple prefix = "pro sin")', function () { |
| 1159 | var menu = OwnContainerMenu.create(listMultiPrefix); |
| 1160 | menu._firstActive = true; |
| 1161 | |
| 1162 | menu.limit(2); |
| 1163 | expect(menu.prefix("pro sin").show()).toBe(true); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1164 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1165 | expect(liElements[0].innerHTML).toEqual( |
| 1166 | "Personal <mark>Pro</mark>noun, <mark>Sin</mark>gular" |
| 1167 | ); |
| 1168 | |
| 1169 | expect(menu.shownItem(0).active()).toBe(true); |
| 1170 | expect(liElements[1].innerHTML).toEqual("Personal <mark>Pro</mark>noun, <mark>Sin</mark>gular, Accusative"); |
| 1171 | expect(menu.shownItem(1).active()).toBe(false); |
| 1172 | |
| 1173 | expect(menu.shownItem(2)).toBe(undefined); |
| 1174 | }); |
| 1175 | |
| 1176 | it('should be filterable (trimming = " p")', function () { |
| 1177 | var menu = OwnContainerMenu.create(listMultiPrefix); |
| 1178 | // menu._firstActive = true; |
| 1179 | |
| 1180 | menu.limit(2); |
| 1181 | expect(menu.show()).toBe(true); |
| 1182 | menu._prefix.add(" "); |
| 1183 | expect(menu.show()).toBe(true); |
| 1184 | menu._prefix.add("p") |
| 1185 | expect(menu.show()).toBe(true); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1186 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1187 | expect(liElements[0].innerHTML).toEqual("<mark>P</mark>ersonal <mark>P</mark>ronoun"); |
| 1188 | }); |
| 1189 | |
| 1190 | |
| 1191 | it('should choose prefix with failing prefix (1)', function () { |
| 1192 | var menu = OwnContainerMenu.create(list); |
| 1193 | menu.limit(2); |
| 1194 | expect(menu.prefix("exit").show()).toBe(true); |
| 1195 | expect(menu.element().querySelector('li')).toBe(null); |
| 1196 | expect(menu.shownItem(0)).toBeUndefined(); |
| 1197 | expect(menu._prefix.active()).toBe(true); |
| 1198 | }); |
| 1199 | |
| 1200 | |
| 1201 | it('should choose prefix with failing prefix (2)', function () { |
| 1202 | var menu = OwnContainerMenu.create(list); |
| 1203 | menu.limit(2); |
| 1204 | expect(menu.show()).toBe(true); |
| 1205 | expect(menu.prefix("exit").show()).toBe(true); |
| 1206 | expect(menu.element().querySelector('li')).toBe(null); |
| 1207 | expect(menu.shownItem(0)).toBeUndefined(); |
| 1208 | expect(menu._prefix.active()).toBe(true); |
| 1209 | }); |
| 1210 | |
| 1211 | it('should ignore navigation with failing prefix', function () { |
| 1212 | var menu = OwnContainerMenu.create(list); |
| 1213 | menu.limit(2); |
| 1214 | expect(menu.show()).toBe(true); |
| 1215 | |
| 1216 | menu.next(); |
| 1217 | |
| 1218 | expect(menu.prefix("exit").show()).toBe(true); |
| 1219 | expect(menu.element().querySelector('li')).toBe(null); |
| 1220 | expect(menu.shownItem(0)).toBeUndefined(); |
| 1221 | expect(menu._prefix.active()).toBe(true); |
| 1222 | |
| 1223 | menu.next(); |
| 1224 | expect(menu._prefix.active()).toBe(true); |
| 1225 | |
| 1226 | menu.prev(); |
| 1227 | expect(menu._prefix.active()).toBe(true); |
| 1228 | |
| 1229 | }); |
| 1230 | |
| 1231 | it('should be navigatable with prefix', function () { |
| 1232 | var menu = OwnContainerMenu.create(demolist); |
| 1233 | menu._firstActive = true; |
| 1234 | |
| 1235 | menu.limit(3); |
| 1236 | |
| 1237 | expect(menu.show()).toBe(true); |
| 1238 | expect(menu.prefix()).toEqual(""); |
| 1239 | |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1240 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1241 | expect(liElements[0].innerHTML).toEqual("Titel"); |
| 1242 | expect(menu.shownItem(0).active()).toBe(true); |
| 1243 | expect(liElements[1].innerHTML).toEqual("Untertitel"); |
| 1244 | expect(menu.shownItem(1).active()).toBe(false); |
| 1245 | expect(liElements[2].innerHTML).toEqual("Veröffentlichungsdatum"); |
| 1246 | expect(menu.shownItem(2).active()).toBe(false); |
| 1247 | expect(menu.shownItem(3)).toBe(undefined); |
| 1248 | |
| 1249 | menu._prefix.add('a'); |
| 1250 | expect(menu.show()).toBe(true); |
| 1251 | expect(menu.prefix()).toEqual("a"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1252 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1253 | expect(liElements[0].innerHTML).toEqual("<mark>A</mark>utor"); |
| 1254 | |
| 1255 | menu._prefix.add('u'); |
| 1256 | expect(menu.show()).toBe(true); |
| 1257 | expect(menu.prefix()).toEqual("au"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1258 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1259 | expect(liElements[0].innerHTML).toEqual("<mark>Au</mark>tor"); |
| 1260 | |
| 1261 | menu._prefix.chop(); |
| 1262 | expect(menu.show()).toBe(true); |
| 1263 | expect(menu.prefix()).toEqual("a"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1264 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1265 | expect(liElements[0].innerHTML).toEqual("<mark>A</mark>utor"); |
| 1266 | |
| 1267 | menu._prefix.chop(); |
| 1268 | expect(menu.show()).toBe(true); |
| 1269 | expect(menu.prefix()).toEqual(""); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1270 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1271 | expect(liElements[0].innerHTML).toEqual("Titel"); |
| 1272 | expect(menu.shownItem(0).active()).toBe(true); |
| 1273 | expect(liElements[1].innerHTML).toEqual("Untertitel"); |
| 1274 | expect(menu.shownItem(1).active()).toBe(false); |
| 1275 | expect(liElements[2].innerHTML).toEqual("Veröffentlichungsdatum"); |
| 1276 | expect(menu.shownItem(2).active()).toBe(false); |
| 1277 | expect(menu.shownItem(3)).toBe(undefined); |
| 1278 | |
| 1279 | // Forward |
| 1280 | menu._prefix.chop(); |
| 1281 | expect(menu.show()).toBe(true); |
| 1282 | expect(menu.prefix()).toEqual(""); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1283 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1284 | expect(liElements[0].innerHTML).toEqual("Titel"); |
| 1285 | expect(menu.shownItem(0).active()).toBe(true); |
| 1286 | expect(liElements[1].innerHTML).toEqual("Untertitel"); |
| 1287 | expect(menu.shownItem(1).active()).toBe(false); |
| 1288 | expect(liElements[2].innerHTML).toEqual("Veröffentlichungsdatum"); |
| 1289 | expect(menu.shownItem(2).active()).toBe(false); |
| 1290 | |
| 1291 | // Forward |
| 1292 | menu.next(); |
| 1293 | expect(menu.prefix()).toEqual(""); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1294 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1295 | expect(liElements[0].innerHTML).toEqual("Titel"); |
| 1296 | expect(menu.shownItem(0).active()).toBe(false); |
| 1297 | expect(liElements[1].innerHTML).toEqual("Untertitel"); |
| 1298 | expect(menu.shownItem(1).active()).toBe(true); |
| 1299 | expect(liElements[2].innerHTML).toEqual("Veröffentlichungsdatum"); |
| 1300 | expect(menu.shownItem(2).active()).toBe(false); |
| 1301 | expect(menu.shownItem(3)).toBe(undefined); |
| 1302 | |
| 1303 | // Forward |
| 1304 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1305 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1306 | expect(menu.prefix()).toEqual(""); |
| 1307 | expect(liElements[0].innerHTML).toEqual("Titel"); |
| 1308 | expect(menu.shownItem(0).active()).toBe(false); |
| 1309 | expect(liElements[1].innerHTML).toEqual("Untertitel"); |
| 1310 | expect(menu.shownItem(1).active()).toBe(false); |
| 1311 | expect(liElements[2].innerHTML).toEqual("Veröffentlichungsdatum"); |
| 1312 | expect(menu.shownItem(2).active()).toBe(true); |
| 1313 | expect(menu.shownItem(3)).toBe(undefined); |
| 1314 | |
| 1315 | // Forward |
| 1316 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1317 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1318 | expect(menu.prefix()).toEqual(""); |
| 1319 | expect(liElements[0].innerHTML).toEqual("Untertitel"); |
| 1320 | expect(menu.shownItem(0).active()).toBe(false); |
| 1321 | expect(liElements[1].innerHTML).toEqual("Veröffentlichungsdatum"); |
| 1322 | expect(menu.shownItem(1).active()).toBe(false); |
| 1323 | expect(liElements[2].innerHTML).toEqual("Länge"); |
| 1324 | expect(menu.shownItem(2).active()).toBe(true); |
| 1325 | expect(menu.shownItem(3)).toBe(undefined); |
| 1326 | |
| 1327 | // Forward |
| 1328 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1329 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1330 | expect(menu.prefix()).toEqual(""); |
| 1331 | expect(liElements[0].innerHTML).toEqual("Veröffentlichungsdatum"); |
| 1332 | expect(menu.shownItem(0).active()).toBe(false); |
| 1333 | expect(liElements[1].innerHTML).toEqual("Länge"); |
| 1334 | expect(menu.shownItem(1).active()).toBe(false); |
| 1335 | expect(liElements[2].innerHTML).toEqual("Autor"); |
| 1336 | expect(menu.shownItem(2).active()).toBe(true); |
| 1337 | expect(menu.shownItem(3)).toBe(undefined); |
| 1338 | |
| 1339 | // Forward |
| 1340 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1341 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1342 | expect(menu.prefix()).toEqual(""); |
| 1343 | expect(liElements[0].innerHTML).toEqual("Titel"); |
| 1344 | expect(menu.shownItem(0).active()).toBe(true); |
| 1345 | expect(liElements[1].innerHTML).toEqual("Untertitel"); |
| 1346 | expect(menu.shownItem(1).active()).toBe(false); |
| 1347 | expect(liElements[2].innerHTML).toEqual("Veröffentlichungsdatum"); |
| 1348 | expect(menu.shownItem(2).active()).toBe(false); |
| 1349 | }); |
| 1350 | |
| 1351 | it('should be navigatable with prefix and containerItems', function () { |
| 1352 | var menu = OwnContainerMenu.create(demolist,ExampleItemList); |
| 1353 | menu._firstActive = true; |
| 1354 | |
| 1355 | menu.limit(3); |
| 1356 | |
| 1357 | expect(menu.show()).toBe(true); |
| 1358 | expect(menu.prefix()).toEqual(""); |
| 1359 | |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1360 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1361 | expect(liElements[0].innerHTML).toEqual("Titel"); |
| 1362 | expect(menu.shownItem(0).active()).toBe(true); |
| 1363 | expect(liElements[1].innerHTML).toEqual("Untertitel"); |
| 1364 | expect(menu.shownItem(1).active()).toBe(false); |
| 1365 | expect(liElements[2].innerHTML).toEqual("Veröffentlichungsdatum"); |
| 1366 | expect(menu.shownItem(2).active()).toBe(false); |
| 1367 | expect(menu.shownItem(3)).toBe(undefined); |
| 1368 | expect(menu.container().items[0].active()).toBe(false); |
| 1369 | expect(menu.container().items[1].active()).toBe(false); |
| 1370 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1371 | |
| 1372 | menu._prefix.add('a'); |
| 1373 | expect(menu.show()).toBe(true); |
| 1374 | expect(menu.prefix()).toEqual("a"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1375 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1376 | expect(liElements[0].innerHTML).toEqual("<mark>A</mark>utor"); |
| 1377 | expect(menu.container().items[0].active()).toBe(false); |
| 1378 | expect(menu.container().items[1].active()).toBe(false); |
| 1379 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1380 | |
| 1381 | menu._prefix.add('u'); |
| 1382 | expect(menu.show()).toBe(true); |
| 1383 | expect(menu.prefix()).toEqual("au"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1384 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1385 | expect(liElements[0].innerHTML).toEqual("<mark>Au</mark>tor"); |
| 1386 | expect(menu.container().items[0].active()).toBe(false); |
| 1387 | expect(menu.container().items[1].active()).toBe(false); |
| 1388 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1389 | |
| 1390 | menu._prefix.chop(); |
| 1391 | expect(menu.show()).toBe(true); |
| 1392 | expect(menu.prefix()).toEqual("a"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1393 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1394 | expect(liElements[0].innerHTML).toEqual("<mark>A</mark>utor"); |
| 1395 | expect(menu.container().items[0].active()).toBe(false); |
| 1396 | expect(menu.container().items[1].active()).toBe(false); |
| 1397 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1398 | |
| 1399 | menu._prefix.chop(); |
| 1400 | expect(menu.show()).toBe(true); |
| 1401 | expect(menu.prefix()).toEqual(""); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1402 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1403 | expect(liElements[0].innerHTML).toEqual("Titel"); |
| 1404 | expect(menu.shownItem(0).active()).toBe(true); |
| 1405 | expect(liElements[1].innerHTML).toEqual("Untertitel"); |
| 1406 | expect(menu.shownItem(1).active()).toBe(false); |
| 1407 | expect(liElements[2].innerHTML).toEqual("Veröffentlichungsdatum"); |
| 1408 | expect(menu.shownItem(2).active()).toBe(false); |
| 1409 | expect(menu.shownItem(3)).toBe(undefined); |
| 1410 | expect(menu.container().items[0].active()).toBe(false); |
| 1411 | expect(menu.container().items[1].active()).toBe(false); |
| 1412 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1413 | |
| 1414 | // Forward |
| 1415 | menu._prefix.chop(); |
| 1416 | expect(menu.show()).toBe(true); |
| 1417 | expect(menu.prefix()).toEqual(""); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1418 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1419 | expect(liElements[0].innerHTML).toEqual("Titel"); |
| 1420 | expect(menu.shownItem(0).active()).toBe(true); |
| 1421 | expect(liElements[1].innerHTML).toEqual("Untertitel"); |
| 1422 | expect(menu.shownItem(1).active()).toBe(false); |
| 1423 | expect(liElements[2].innerHTML).toEqual("Veröffentlichungsdatum"); |
| 1424 | expect(menu.shownItem(2).active()).toBe(false); |
| 1425 | expect(menu.container().items[0].active()).toBe(false); |
| 1426 | expect(menu.container().items[1].active()).toBe(false); |
| 1427 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1428 | |
| 1429 | // Forward |
| 1430 | menu.next(); |
| 1431 | expect(menu.prefix()).toEqual(""); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1432 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1433 | expect(liElements[0].innerHTML).toEqual("Titel"); |
| 1434 | expect(menu.shownItem(0).active()).toBe(false); |
| 1435 | expect(liElements[1].innerHTML).toEqual("Untertitel"); |
| 1436 | expect(menu.shownItem(1).active()).toBe(true); |
| 1437 | expect(liElements[2].innerHTML).toEqual("Veröffentlichungsdatum"); |
| 1438 | expect(menu.shownItem(2).active()).toBe(false); |
| 1439 | expect(menu.shownItem(3)).toBe(undefined); |
| 1440 | expect(menu.container().items[0].active()).toBe(false); |
| 1441 | expect(menu.container().items[1].active()).toBe(false); |
| 1442 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1443 | |
| 1444 | // Forward |
| 1445 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1446 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1447 | expect(menu.prefix()).toEqual(""); |
| 1448 | expect(liElements[0].innerHTML).toEqual("Titel"); |
| 1449 | expect(menu.shownItem(0).active()).toBe(false); |
| 1450 | expect(liElements[1].innerHTML).toEqual("Untertitel"); |
| 1451 | expect(menu.shownItem(1).active()).toBe(false); |
| 1452 | expect(liElements[2].innerHTML).toEqual("Veröffentlichungsdatum"); |
| 1453 | expect(menu.shownItem(2).active()).toBe(true); |
| 1454 | expect(menu.shownItem(3)).toBe(undefined); |
| 1455 | expect(menu.container().items[0].active()).toBe(false); |
| 1456 | expect(menu.container().items[1].active()).toBe(false); |
| 1457 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1458 | |
| 1459 | // Forward |
| 1460 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1461 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1462 | expect(menu.prefix()).toEqual(""); |
| 1463 | expect(liElements[0].innerHTML).toEqual("Untertitel"); |
| 1464 | expect(menu.shownItem(0).active()).toBe(false); |
| 1465 | expect(liElements[1].innerHTML).toEqual("Veröffentlichungsdatum"); |
| 1466 | expect(menu.shownItem(1).active()).toBe(false); |
| 1467 | expect(liElements[2].innerHTML).toEqual("Länge"); |
| 1468 | expect(menu.shownItem(2).active()).toBe(true); |
| 1469 | expect(menu.shownItem(3)).toBe(undefined); |
| 1470 | expect(menu.container().items[0].active()).toBe(false); |
| 1471 | expect(menu.container().items[1].active()).toBe(false); |
| 1472 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1473 | |
| 1474 | // Forward |
| 1475 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1476 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1477 | expect(menu.prefix()).toEqual(""); |
| 1478 | expect(liElements[0].innerHTML).toEqual("Veröffentlichungsdatum"); |
| 1479 | expect(menu.shownItem(0).active()).toBe(false); |
| 1480 | expect(liElements[1].innerHTML).toEqual("Länge"); |
| 1481 | expect(menu.shownItem(1).active()).toBe(false); |
| 1482 | expect(liElements[2].innerHTML).toEqual("Autor"); |
| 1483 | expect(menu.shownItem(2).active()).toBe(true); |
| 1484 | expect(menu.shownItem(3)).toBe(undefined); |
| 1485 | expect(menu.container().items[0].active()).toBe(false); |
| 1486 | expect(menu.container().items[1].active()).toBe(false); |
| 1487 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1488 | |
| 1489 | // Forward |
| 1490 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1491 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1492 | expect(menu.prefix()).toEqual(""); |
| 1493 | expect(liElements[0].innerHTML).toEqual("Veröffentlichungsdatum"); |
| 1494 | expect(menu.shownItem(0).active()).toBe(false); |
| 1495 | expect(liElements[1].innerHTML).toEqual("Länge"); |
| 1496 | expect(menu.shownItem(1).active()).toBe(false); |
| 1497 | expect(liElements[2].innerHTML).toEqual("Autor"); |
| 1498 | expect(menu.shownItem(2).active()).toBe(false); |
| 1499 | expect(menu.shownItem(3)).toBe(undefined); |
| 1500 | expect(menu.container().items[0].active()).toBe(true); |
| 1501 | expect(menu.container().items[1].active()).toBe(false); |
| 1502 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1503 | |
| 1504 | // Forward |
| 1505 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1506 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1507 | expect(menu.prefix()).toEqual(""); |
| 1508 | expect(liElements[0].innerHTML).toEqual("Veröffentlichungsdatum"); |
| 1509 | expect(menu.shownItem(0).active()).toBe(false); |
| 1510 | expect(liElements[1].innerHTML).toEqual("Länge"); |
| 1511 | expect(menu.shownItem(1).active()).toBe(false); |
| 1512 | expect(liElements[2].innerHTML).toEqual("Autor"); |
| 1513 | expect(menu.shownItem(2).active()).toBe(false); |
| 1514 | expect(menu.shownItem(3)).toBe(undefined); |
| 1515 | expect(menu.container().items[0].active()).toBe(false); |
| 1516 | expect(menu.container().items[1].active()).toBe(true); |
| 1517 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1518 | |
| 1519 | // Forward |
| 1520 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1521 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1522 | expect(menu.prefix()).toEqual(""); |
| 1523 | expect(liElements[0].innerHTML).toEqual("Titel"); |
| 1524 | expect(menu.shownItem(0).active()).toBe(true); |
| 1525 | expect(liElements[1].innerHTML).toEqual("Untertitel"); |
| 1526 | expect(menu.shownItem(1).active()).toBe(false); |
| 1527 | expect(liElements[2].innerHTML).toEqual("Veröffentlichungsdatum"); |
| 1528 | expect(menu.shownItem(2).active()).toBe(false); |
| 1529 | expect(menu.container().items[0].active()).toBe(false); |
| 1530 | expect(menu.container().items[1].active()).toBe(false); |
| 1531 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1532 | }); |
| 1533 | |
| 1534 | it('should be navigatable with a prefix (1) and containerItems', function () { |
| 1535 | var menu = OwnContainerMenu.create(demolist, ExampleItemList); |
| 1536 | menu._firstActive = true; |
| 1537 | |
| 1538 | menu.limit(3); |
| 1539 | |
| 1540 | expect(menu.show()).toBe(true); |
| 1541 | expect(menu.prefix()).toEqual(""); |
| 1542 | |
| 1543 | // Add prefix in uppercase - but check in lowercase |
| 1544 | menu.prefix('El'); |
| 1545 | expect(menu.show()).toBe(true); |
| 1546 | |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1547 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1548 | expect(menu.prefix()).toEqual("El"); |
| 1549 | expect(menu._prefix.active()).toEqual(false); |
| 1550 | expect(liElements[0].innerHTML).toEqual("Tit<mark>el</mark>"); |
| 1551 | expect(menu.shownItem(0).active()).toBe(true); |
| 1552 | expect(liElements[1].innerHTML).toEqual("Untertit<mark>el</mark>"); |
| 1553 | expect(menu.shownItem(1).active()).toBe(false); |
| 1554 | expect(menu.shownItem(2)).toBe(undefined); |
| 1555 | expect(menu.container().items[0].active()).toBe(false); |
| 1556 | expect(menu.container().items[1].active()).toBe(false); |
| 1557 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1558 | |
| 1559 | // Forward |
| 1560 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1561 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1562 | expect(menu.prefix()).toEqual("El"); |
| 1563 | expect(menu._prefix.active()).toEqual(false); |
| 1564 | expect(liElements[0].innerHTML).toEqual("Tit<mark>el</mark>"); |
| 1565 | expect(menu.shownItem(0).active()).toBe(false); |
| 1566 | expect(liElements[1].innerHTML).toEqual("Untertit<mark>el</mark>"); |
| 1567 | expect(menu.shownItem(1).active()).toBe(true); |
| 1568 | expect(menu.shownItem(2)).toBe(undefined); |
| 1569 | expect(menu.container().items[0].active()).toBe(false); |
| 1570 | expect(menu.container().items[1].active()).toBe(false); |
| 1571 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1572 | |
| 1573 | // Forward |
| 1574 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1575 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1576 | expect(menu.prefix()).toEqual("El"); |
| 1577 | expect(liElements[0].innerHTML).toEqual("Tit<mark>el</mark>"); |
| 1578 | expect(menu.shownItem(0).active()).toBe(false); |
| 1579 | expect(liElements[1].innerHTML).toEqual("Untertit<mark>el</mark>"); |
| 1580 | expect(menu.shownItem(1).active()).toBe(false); |
| 1581 | expect(menu.shownItem(2)).toBe(undefined); |
| 1582 | expect(menu.container().items[0].active()).toBe(true); |
| 1583 | expect(menu.container().items[1].active()).toBe(false); |
| 1584 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1585 | |
| 1586 | menu.next(); |
| 1587 | menu.next(); |
| 1588 | |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1589 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1590 | expect(menu.prefix()).toEqual("El"); |
| 1591 | expect(liElements[0].innerHTML).toEqual("Tit<mark>el</mark>"); |
| 1592 | expect(menu.shownItem(0).active()).toBe(false); |
| 1593 | expect(liElements[1].innerHTML).toEqual("Untertit<mark>el</mark>"); |
| 1594 | expect(menu.shownItem(1).active()).toBe(false); |
| 1595 | expect(menu.shownItem(2)).toBe(undefined); |
| 1596 | expect(menu.container().items[0].active()).toBe(false); |
| 1597 | expect(menu.container().items[1].active()).toBe(false); |
| 1598 | expect(menu.container().items[2].active()).toBe(true); //prefix |
| 1599 | |
| 1600 | // Backward |
| 1601 | menu.prev(); |
| 1602 | menu.prev(); |
| 1603 | menu.prev(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1604 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1605 | expect(menu.prefix()).toEqual("El"); |
| 1606 | expect(menu._prefix.active()).toEqual(false); |
| 1607 | expect(liElements[0].innerHTML).toEqual("Tit<mark>el</mark>"); |
| 1608 | expect(menu.shownItem(0).active()).toBe(false); |
| 1609 | expect(liElements[1].innerHTML).toEqual("Untertit<mark>el</mark>"); |
| 1610 | expect(menu.shownItem(1).active()).toBe(true); |
| 1611 | expect(menu.shownItem(2)).toBe(undefined); |
| 1612 | expect(menu.container().items[0].active()).toBe(false); |
| 1613 | expect(menu.container().items[1].active()).toBe(false); |
| 1614 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1615 | }); |
| 1616 | |
| 1617 | |
| 1618 | it('should be navigatable with a prefix (2) and containerItems', function () { |
| 1619 | var menu = OwnContainerMenu.create(demolist,ExampleItemList); |
| 1620 | menu._firstActive = true; |
| 1621 | |
| 1622 | menu.limit(3); |
| 1623 | expect(menu.show()).toBe(true); |
| 1624 | expect(menu.prefix()).toEqual(""); |
| 1625 | menu.prefix('el'); |
| 1626 | expect(menu.show()).toBe(true); |
| 1627 | |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1628 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1629 | expect(menu.prefix()).toEqual("el"); |
| 1630 | expect(menu._prefix.active()).toEqual(false); |
| 1631 | expect(liElements[0].innerHTML).toEqual("Tit<mark>el</mark>"); |
| 1632 | expect(menu.shownItem(0).active()).toBe(true); |
| 1633 | expect(liElements[1].innerHTML).toEqual("Untertit<mark>el</mark>"); |
| 1634 | expect(menu.shownItem(1).active()).toBe(false); |
| 1635 | expect(menu.shownItem(2)).toBe(undefined); |
| 1636 | expect(menu.container().items[0].active()).toBe(false); |
| 1637 | expect(menu.container().items[1].active()).toBe(false); |
| 1638 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1639 | |
| 1640 | // Backward |
| 1641 | menu.prev(); |
| 1642 | expect(menu._prefix.active()).toEqual(true); |
| 1643 | |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1644 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1645 | expect(liElements[0].innerHTML).toEqual("Tit<mark>el</mark>"); |
| 1646 | expect(menu.shownItem(0).active()).toBe(false); |
| 1647 | expect(liElements[1].innerHTML).toEqual("Untertit<mark>el</mark>"); |
| 1648 | expect(menu.shownItem(1).active()).toBe(false); |
| 1649 | expect(menu.shownItem(2)).toBe(undefined); |
| 1650 | expect(menu.container().items[0].active()).toBe(false); |
| 1651 | expect(menu.container().items[1].active()).toBe(false); |
| 1652 | expect(menu.container().items[2].active()).toBe(true); //prefix |
| 1653 | |
| 1654 | // Backward |
| 1655 | menu.prev(); |
| 1656 | menu.prev(); |
| 1657 | menu.prev(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1658 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1659 | expect(menu._prefix.active()).toEqual(false); |
| 1660 | expect(liElements[0].innerHTML).toEqual("Tit<mark>el</mark>"); |
| 1661 | expect(menu.shownItem(0).active()).toBe(false); |
| 1662 | expect(liElements[1].innerHTML).toEqual("Untertit<mark>el</mark>"); |
| 1663 | expect(menu.shownItem(1).active()).toBe(true); |
| 1664 | expect(menu.shownItem(2)).toBe(undefined); |
| 1665 | expect(menu.container().items[0].active()).toBe(false); |
| 1666 | expect(menu.container().items[1].active()).toBe(false); |
| 1667 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1668 | }); |
| 1669 | |
| 1670 | it('should be navigatable with a prefix (3) and containerItems', function () { |
| 1671 | var menu = OwnContainerMenu.create(demolist,ExampleItemList); |
| 1672 | menu._firstActive = true; |
| 1673 | menu.limit(3); |
| 1674 | expect(menu.show()).toBe(true); |
| 1675 | expect(menu.prefix()).toEqual(""); |
| 1676 | menu.prefix('el'); |
| 1677 | expect(menu.show()).toBe(true); |
| 1678 | |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1679 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1680 | expect(menu.prefix()).toEqual("el"); |
| 1681 | expect(menu._prefix.active()).toEqual(false); |
| 1682 | expect(liElements[0].innerHTML).toEqual("Tit<mark>el</mark>"); |
| 1683 | expect(menu.shownItem(0).active()).toBe(true); |
| 1684 | expect(liElements[1].innerHTML).toEqual("Untertit<mark>el</mark>"); |
| 1685 | expect(menu.shownItem(1).active()).toBe(false); |
| 1686 | expect(menu.shownItem(2)).toBe(undefined); |
| 1687 | expect(menu.container().items[0].active()).toBe(false); |
| 1688 | expect(menu.container().items[1].active()).toBe(false); |
| 1689 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1690 | |
| 1691 | // Backward |
| 1692 | menu.prev(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1693 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1694 | expect(menu._prefix.active()).toEqual(true); |
| 1695 | expect(liElements[0].innerHTML).toEqual("Tit<mark>el</mark>"); |
| 1696 | expect(menu.shownItem(0).active()).toBe(false); |
| 1697 | expect(liElements[1].innerHTML).toEqual("Untertit<mark>el</mark>"); |
| 1698 | expect(menu.shownItem(1).active()).toBe(false); |
| 1699 | expect(menu.shownItem(2)).toBe(undefined); |
| 1700 | expect(menu.container().items[0].active()).toBe(false); |
| 1701 | expect(menu.container().items[1].active()).toBe(false); |
| 1702 | expect(menu.container().items[2].active()).toBe(true); //prefix |
| 1703 | |
| 1704 | |
| 1705 | // Forward |
| 1706 | menu.next(); |
| 1707 | expect(menu.prefix()).toEqual("el"); |
| 1708 | expect(menu._prefix.active()).toEqual(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1709 | var liElements = directElementChildrenByTagName(menu.element(),"li"); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 1710 | expect(liElements[0].innerHTML).toEqual("Tit<mark>el</mark>"); |
| 1711 | expect(menu.shownItem(0).active()).toBe(true); |
| 1712 | expect(liElements[1].innerHTML).toEqual("Untertit<mark>el</mark>"); |
| 1713 | expect(menu.shownItem(1).active()).toBe(false); |
| 1714 | expect(menu.shownItem(2)).toBe(undefined); |
| 1715 | expect(menu.container().items[0].active()).toBe(false); |
| 1716 | expect(menu.container().items[1].active()).toBe(false); |
| 1717 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1718 | |
| 1719 | }); |
| 1720 | |
| 1721 | it('should show screens by offset', function () { |
| 1722 | var menu = OwnContainerMenu.create(demolist,ExampleItemList); |
| 1723 | menu.limit(3); |
| 1724 | expect(menu.show()).toBe(true); |
| 1725 | |
| 1726 | expect(menu.shownItem(0).active()).toBe(false); |
| 1727 | expect(menu.shownItem(1).active()).toBe(false); |
| 1728 | expect(menu.shownItem(2).active()).toBe(false); |
| 1729 | expect(menu.container().items[0].active()).toBe(false); |
| 1730 | expect(menu.container().items[1].active()).toBe(false); |
| 1731 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1732 | |
| 1733 | // Highlight the first entry |
| 1734 | menu.next(); |
| 1735 | |
| 1736 | expect(menu.shownItem(0).active()).toBe(true); |
| 1737 | expect(menu.shownItem(1).active()).toBe(false); |
| 1738 | expect(menu.shownItem(2).active()).toBe(false); |
| 1739 | |
| 1740 | // Highlight the second entry |
| 1741 | menu.next(); |
| 1742 | |
| 1743 | expect(menu.shownItem(0).active()).toBe(false); |
| 1744 | expect(menu.shownItem(1).active()).toBe(true); |
| 1745 | expect(menu.shownItem(2).active()).toBe(false); |
| 1746 | expect(menu.shownItem(3)).toBe(undefined); |
| 1747 | |
| 1748 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1749 | expect(menu.shownItem(1).lcField()).toEqual(' untertitel'); |
| 1750 | |
| 1751 | // Move to first screen |
| 1752 | menu.screen(0); |
| 1753 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1754 | expect(menu.shownItem(1).lcField()).toEqual(' untertitel'); |
| 1755 | expect(menu.shownItem(0).active()).toBe(false); |
| 1756 | expect(menu.shownItem(1).active()).toBe(true); |
| 1757 | expect(menu.shownItem(2).active()).toBe(false); |
| 1758 | expect(menu.shownItem(3)).toBe(undefined); |
| 1759 | |
| 1760 | // Move to second screen |
| 1761 | menu.screen(1); |
| 1762 | expect(menu.shownItem(0).lcField()).toEqual(' untertitel'); |
| 1763 | expect(menu.shownItem(0).active()).toBe(true); |
| 1764 | expect(menu.shownItem(1).active()).toBe(false); |
| 1765 | expect(menu.shownItem(2).active()).toBe(false); |
| 1766 | expect(menu.shownItem(3)).toBe(undefined); |
| 1767 | |
| 1768 | menu.screen(2); |
| 1769 | expect(menu.shownItem(0).lcField()).toEqual(' veröffentlichungsdatum'); |
| 1770 | expect(menu.shownItem(0).active()).toBe(false); |
| 1771 | expect(menu.shownItem(1).active()).toBe(false); |
| 1772 | expect(menu.shownItem(2).active()).toBe(false); |
| 1773 | expect(menu.shownItem(3)).toBe(undefined); |
| 1774 | |
| 1775 | menu.screen(1); |
| 1776 | expect(menu.shownItem(0).lcField()).toEqual(' untertitel'); |
| 1777 | expect(menu.shownItem(0).active()).toBe(true); |
| 1778 | expect(menu.shownItem(1).active()).toBe(false); |
| 1779 | expect(menu.shownItem(2).active()).toBe(false); |
| 1780 | expect(menu.shownItem(3)).toBe(undefined); |
| 1781 | expect(menu.container().items[0].active()).toBe(false); |
| 1782 | expect(menu.container().items[1].active()).toBe(false); |
| 1783 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1784 | }); |
| 1785 | |
| 1786 | it('should show screens by offset when prefixed', function () { |
| 1787 | var menu = OwnContainerMenu.create(demolist,ExampleItemList); |
| 1788 | menu.limit(3); |
| 1789 | expect(menu.prefix("e").show()).toBe(true); |
| 1790 | expect(menu.shownItem(0).active()).toBe(false); |
| 1791 | expect(menu.shownItem(1).active()).toBe(false); |
| 1792 | expect(menu.shownItem(2).active()).toBe(false); |
| 1793 | expect(menu.container().items[0].active()).toBe(false); |
| 1794 | expect(menu.container().items[1].active()).toBe(false); |
| 1795 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1796 | |
| 1797 | expect(menu.shownItem(0).element().innerHTML).toEqual('Tit<mark>e</mark>l'); |
| 1798 | menu.screen(1); |
| 1799 | expect(menu.shownItem(0).element().innerHTML).toEqual('Unt<mark>e</mark>rtit<mark>e</mark>l'); |
| 1800 | }); |
| 1801 | |
| 1802 | |
| 1803 | it('should be page downable', function () { |
| 1804 | var menu = OwnContainerMenu.create(demolonglist,ExampleItemList); |
| 1805 | menu.limit(3); |
| 1806 | |
| 1807 | expect(menu.show(0)).toBe(true); |
| 1808 | |
| 1809 | expect(menu.container().items[0].active()).toBe(false); |
| 1810 | expect(menu.container().items[1].active()).toBe(false); |
| 1811 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1812 | |
| 1813 | expect(menu.shownItem(0).active()).toBe(true); |
| 1814 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1815 | expect(menu.shownItem(1).active()).toBe(false); |
| 1816 | expect(menu.shownItem(2).active()).toBe(false); |
| 1817 | expect(menu.shownItem(3)).toBe(undefined); |
| 1818 | |
| 1819 | menu.pageDown(); |
| 1820 | |
| 1821 | expect(menu.shownItem(0).lcField()).toEqual(' länge'); |
| 1822 | expect(menu.shownItem(0).active()).toBe(false); |
| 1823 | expect(menu.shownItem(1).active()).toBe(false); |
| 1824 | expect(menu.shownItem(2).active()).toBe(false); |
| 1825 | |
| 1826 | menu.pageDown(); |
| 1827 | |
| 1828 | expect(menu.shownItem(0).lcField()).toEqual(' corpusid'); |
| 1829 | expect(menu.shownItem(0).active()).toBe(false); |
| 1830 | expect(menu.shownItem(1).active()).toBe(false); |
| 1831 | expect(menu.shownItem(2).active()).toBe(false); |
| 1832 | |
| 1833 | // Doesn't matter |
| 1834 | menu.pageDown(); |
| 1835 | |
| 1836 | expect(menu.shownItem(0).lcField()).toEqual(' corpusid'); |
| 1837 | expect(menu.shownItem(0).active()).toBe(false); |
| 1838 | expect(menu.shownItem(1).active()).toBe(false); |
| 1839 | expect(menu.shownItem(2).active()).toBe(false); |
| 1840 | expect(menu.container().items[0].active()).toBe(false); |
| 1841 | expect(menu.container().items[1].active()).toBe(false); |
| 1842 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1843 | }); |
| 1844 | |
| 1845 | it('should be page downable with prefix', function () { |
| 1846 | var menu = OwnContainerMenu.create(demolonglist,ExampleItemList); |
| 1847 | menu.limit(3); |
| 1848 | |
| 1849 | expect(menu.prefix('e').show(0)).toBe(true); |
| 1850 | |
| 1851 | expect(menu.shownItem(0).active()).toBe(true); |
| 1852 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1853 | expect(menu.shownItem(1).active()).toBe(false); |
| 1854 | expect(menu.shownItem(1).lcField()).toEqual(' untertitel'); |
| 1855 | expect(menu.shownItem(2).active()).toBe(false); |
| 1856 | expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum'); |
| 1857 | expect(menu.shownItem(3)).toBe(undefined); |
| 1858 | |
| 1859 | expect(menu.container().items[0].active()).toBe(false); |
| 1860 | expect(menu.container().items[1].active()).toBe(false); |
| 1861 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1862 | |
| 1863 | menu.pageDown(); |
| 1864 | |
| 1865 | expect(menu.shownItem(0).active()).toBe(false); |
| 1866 | expect(menu.shownItem(0).lcField()).toEqual(' länge'); |
| 1867 | expect(menu.shownItem(1).active()).toBe(false); |
| 1868 | expect(menu.shownItem(1).lcField()).toEqual(' genre'); |
| 1869 | expect(menu.shownItem(2).active()).toBe(false); |
| 1870 | expect(menu.shownItem(2).lcField()).toEqual(' textid'); |
| 1871 | |
| 1872 | // Doesn't matter |
| 1873 | menu.pageDown(); |
| 1874 | |
| 1875 | expect(menu.shownItem(0).active()).toBe(false); |
| 1876 | expect(menu.shownItem(0).lcField()).toEqual(' länge'); |
| 1877 | expect(menu.shownItem(1).active()).toBe(false); |
| 1878 | expect(menu.shownItem(1).lcField()).toEqual(' genre'); |
| 1879 | expect(menu.shownItem(2).active()).toBe(false); |
| 1880 | expect(menu.shownItem(2).lcField()).toEqual(' textid'); |
| 1881 | expect(menu.container().items[0].active()).toBe(false); |
| 1882 | expect(menu.container().items[1].active()).toBe(false); |
| 1883 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1884 | }); |
| 1885 | |
| 1886 | |
| 1887 | it('should be page upable', function () { |
| 1888 | var menu = OwnContainerMenu.create(demolonglist,ExampleItemList); |
| 1889 | menu.limit(3); |
| 1890 | |
| 1891 | // Choose the final value |
| 1892 | expect(menu.show(1000)).toBe(true); |
| 1893 | |
| 1894 | expect(menu.shownItem(0).active()).toBe(false); |
| 1895 | expect(menu.shownItem(1).active()).toBe(false); |
| 1896 | expect(menu.shownItem(2).active()).toBe(true); |
| 1897 | expect(menu.shownItem(2).lcField()).toEqual(' textid'); |
| 1898 | expect(menu.shownItem(3)).toBe(undefined); |
| 1899 | expect(menu.container().items[0].active()).toBe(false); |
| 1900 | expect(menu.container().items[1].active()).toBe(false); |
| 1901 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1902 | |
| 1903 | menu.pageUp(); |
| 1904 | |
| 1905 | expect(menu.shownItem(0).lcField()).toEqual(' länge'); |
| 1906 | expect(menu.shownItem(0).active()).toBe(false); |
| 1907 | expect(menu.shownItem(1).active()).toBe(false); |
| 1908 | expect(menu.shownItem(2).active()).toBe(false); |
| 1909 | |
| 1910 | menu.pageUp(); |
| 1911 | |
| 1912 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1913 | expect(menu.shownItem(0).active()).toBe(false); |
| 1914 | expect(menu.shownItem(1).active()).toBe(false); |
| 1915 | expect(menu.shownItem(2).active()).toBe(false); |
| 1916 | |
| 1917 | // Doesn't matter |
| 1918 | menu.pageUp(); |
| 1919 | |
| 1920 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1921 | expect(menu.shownItem(0).active()).toBe(false); |
| 1922 | expect(menu.shownItem(1).active()).toBe(false); |
| 1923 | expect(menu.shownItem(2).active()).toBe(false); |
| 1924 | expect(menu.container().items[0].active()).toBe(false); |
| 1925 | expect(menu.container().items[1].active()).toBe(false); |
| 1926 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1927 | }); |
| 1928 | |
| 1929 | it('should be page upable with prefix', function () { |
| 1930 | var menu = OwnContainerMenu.create(demolonglist,ExampleItemList); |
| 1931 | menu.limit(3); |
| 1932 | |
| 1933 | // Choose the final value |
| 1934 | expect(menu.prefix("e").show(1000)).toBe(true); |
| 1935 | |
| 1936 | expect(menu.shownItem(0).active()).toBe(false); |
| 1937 | expect(menu.shownItem(0).lcField()).toEqual(' länge'); |
| 1938 | expect(menu.shownItem(1).active()).toBe(false); |
| 1939 | expect(menu.shownItem(1).lcField()).toEqual(' genre'); |
| 1940 | expect(menu.shownItem(2).active()).toBe(true); |
| 1941 | expect(menu.shownItem(2).lcField()).toEqual(' textid'); |
| 1942 | expect(menu.shownItem(3)).toBe(undefined); |
| 1943 | expect(menu.container().items[0].active()).toBe(false); |
| 1944 | expect(menu.container().items[1].active()).toBe(false); |
| 1945 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1946 | |
| 1947 | menu.pageUp(); |
| 1948 | |
| 1949 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1950 | expect(menu.shownItem(0).active()).toBe(false); |
| 1951 | expect(menu.shownItem(1).active()).toBe(false); |
| 1952 | expect(menu.shownItem(1).lcField()).toEqual(' untertitel'); |
| 1953 | expect(menu.shownItem(2).active()).toBe(false); |
| 1954 | expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum'); |
| 1955 | |
| 1956 | // Doesn't matter |
| 1957 | menu.pageUp(); |
| 1958 | |
| 1959 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1960 | expect(menu.shownItem(0).active()).toBe(false); |
| 1961 | expect(menu.shownItem(1).active()).toBe(false); |
| 1962 | expect(menu.shownItem(1).lcField()).toEqual(' untertitel'); |
| 1963 | expect(menu.shownItem(2).active()).toBe(false); |
| 1964 | expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum'); |
| 1965 | expect(menu.container().items[0].active()).toBe(false); |
| 1966 | expect(menu.container().items[1].active()).toBe(false); |
| 1967 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1968 | }); |
| 1969 | |
| 1970 | it('should be view upable and downable (1)', function () { |
| 1971 | var menu = OwnContainerMenu.create(demolonglist,ExampleItemList); |
| 1972 | menu.limit(7); |
| 1973 | |
| 1974 | // Choose the final value |
| 1975 | expect(menu.show(1)).toBe(true); |
| 1976 | |
| 1977 | expect(menu.shownItem(0).active()).toBe(false); |
| 1978 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1979 | expect(menu.shownItem(1).active()).toBe(true); |
| 1980 | expect(menu.shownItem(2).active()).toBe(false); |
| 1981 | expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum'); |
| 1982 | expect(menu.shownItem(6).active()).toBe(false); |
| 1983 | expect(menu.shownItem(7)).toBe(undefined); |
| 1984 | expect(menu.container().items[0].active()).toBe(false); |
| 1985 | expect(menu.container().items[1].active()).toBe(false); |
| 1986 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 1987 | |
| 1988 | // Doesn't change anything |
| 1989 | menu.viewUp(); |
| 1990 | |
| 1991 | expect(menu.shownItem(0).active()).toBe(false); |
| 1992 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 1993 | expect(menu.shownItem(1).active()).toBe(true); |
| 1994 | |
| 1995 | menu.viewDown(); |
| 1996 | |
| 1997 | expect(menu.shownItem(0).active()).toBe(true); |
| 1998 | expect(menu.shownItem(0).lcField()).toEqual(' untertitel'); |
| 1999 | expect(menu.shownItem(1).active()).toBe(false); |
| 2000 | |
| 2001 | menu.viewDown(); |
| 2002 | |
| 2003 | expect(menu.shownItem(0).active()).toBe(false); |
| 2004 | expect(menu.shownItem(0).lcField()).toEqual(' veröffentlichungsdatum'); |
| 2005 | expect(menu.shownItem(1).active()).toBe(false); |
| 2006 | |
| 2007 | // No effect anymore |
| 2008 | menu.viewDown(); |
| 2009 | |
| 2010 | expect(menu.shownItem(0).active()).toBe(false); |
| 2011 | expect(menu.shownItem(0).lcField()).toEqual(' veröffentlichungsdatum'); |
| 2012 | expect(menu.shownItem(1).active()).toBe(false); |
| 2013 | expect(menu.container().items[0].active()).toBe(false); |
| 2014 | expect(menu.container().items[1].active()).toBe(false); |
| 2015 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 2016 | }); |
| 2017 | |
| 2018 | it('should be view upable and downable (2)', function () { |
| 2019 | |
| 2020 | // List is longer than limit |
| 2021 | var menu = OwnContainerMenu.create(demolist,ExampleItemList); |
| 2022 | menu.limit(7); |
| 2023 | |
| 2024 | // Choose the final value |
| 2025 | expect(menu.show(1)).toBe(true); |
| 2026 | |
| 2027 | expect(menu.shownItem(0).active()).toBe(false); |
| 2028 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 2029 | expect(menu.shownItem(1).active()).toBe(true); |
| 2030 | expect(menu.shownItem(2).active()).toBe(false); |
| 2031 | expect(menu.shownItem(2).lcField()).toEqual(' veröffentlichungsdatum'); |
| 2032 | expect(menu.shownItem(4).active()).toBe(false); |
| 2033 | expect(menu.shownItem(5)).toBe(undefined); |
| 2034 | expect(menu.container().items[0].active()).toBe(false); |
| 2035 | expect(menu.container().items[1].active()).toBe(false); |
| 2036 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 2037 | |
| 2038 | // Doesn't change anything |
| 2039 | menu.viewUp(); |
| 2040 | |
| 2041 | expect(menu.shownItem(0).active()).toBe(false); |
| 2042 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 2043 | expect(menu.shownItem(1).active()).toBe(true); |
| 2044 | |
| 2045 | menu.viewDown(); |
| 2046 | |
| 2047 | expect(menu.shownItem(0).active()).toBe(false); |
| 2048 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 2049 | expect(menu.shownItem(1).active()).toBe(true); |
| 2050 | expect(menu.container().items[0].active()).toBe(false); |
| 2051 | expect(menu.container().items[1].active()).toBe(false); |
| 2052 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 2053 | }); |
| 2054 | |
| 2055 | |
| 2056 | it('should scroll to a chosen value (1)', function () { |
| 2057 | var menu = OwnContainerMenu.create(demolist,ExampleItemList); |
| 2058 | menu.limit(3); |
| 2059 | |
| 2060 | // Choose value 1 |
| 2061 | expect(menu.show(1)).toBe(true); |
| 2062 | |
| 2063 | expect(menu.shownItem(0).active()).toBe(false); |
| 2064 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 2065 | expect(menu.shownItem(1).active()).toBe(true); |
| 2066 | expect(menu.shownItem(2).active()).toBe(false); |
| 2067 | expect(menu.shownItem(3)).toBe(undefined); |
| 2068 | expect(menu.container().items[0].active()).toBe(false); |
| 2069 | expect(menu.container().items[1].active()).toBe(false); |
| 2070 | expect(menu.container().items[2].active()).toBe(false); //prefix |
| 2071 | |
| 2072 | // Choose value 2 |
| 2073 | expect(menu.show(2)).toBe(true); |
| 2074 | |
| 2075 | expect(menu.shownItem(0).active()).toBe(false); |
| 2076 | expect(menu.shownItem(0).lcField()).toEqual(' titel'); |
| 2077 | expect(menu.shownItem(1).active()).toBe(false); |
| 2078 | expect(menu.shownItem(2).active()).toBe(true); |
| 2079 | expect(menu.shownItem(3)).toBe(undefined); |
| 2080 | }); |
| 2081 | |
| 2082 | it('should scroll to a chosen value (2)', function () { |
| 2083 | var menu = OwnContainerMenu.create(demolonglist,ExampleItemList); |
| 2084 | |
| 2085 | // Choose value 3 |
| 2086 | expect(menu.limit(3).show(3)).toBe(true); |
| 2087 | expect(menu.shownItem(0).lcField()).toEqual(' länge'); |
| 2088 | expect(menu.shownItem(0).active()).toBe(true); |
| 2089 | expect(menu.shownItem(1).active()).toBe(false); |
| 2090 | expect(menu.shownItem(2).active()).toBe(false); |
| 2091 | expect(menu.shownItem(3)).toBe(undefined); |
| 2092 | }); |
| 2093 | |
| 2094 | xit('should scroll to a chosen value after prefixing, if the chosen value is live'); |
| 2095 | |
| 2096 | it('should be extendable', function () { |
Leo Repp | 46903bf | 2021-12-18 16:05:53 +0100 | [diff] [blame] | 2097 | var menu = OwnContainerMenu.create([],ExampleItemList); |
| 2098 | let entryData = 'empty'; |
| 2099 | menu._itemClass = menuItemClass; |
| 2100 | menu.readItems([ |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 2101 | ['a', '', function () { entryData = 'a' }], |
| 2102 | ['bb', '', function () { entryData = 'bb' }], |
| 2103 | ['ccc', '', function () { entryData = 'ccc' }], |
| 2104 | ]); |
| 2105 | expect(menu.limit(3).show(3)).toBe(true); |
| 2106 | expect(menu.shownItem(0).lcField()).toEqual(' a'); |
| 2107 | expect(menu.shownItem(1).lcField()).toEqual(' bb'); |
| 2108 | expect(menu.shownItem(2).lcField()).toEqual(' ccc'); |
| 2109 | expect(entryData).toEqual('empty'); |
| 2110 | menu.shownItem(1).element().click(); |
| 2111 | expect(entryData).toEqual('bb'); |
| 2112 | expect(menu.lengthField().element().innerText).toEqual("a--bb--ccc--") |
| 2113 | expect(menu.slider().length()).toEqual(3); |
| 2114 | let obj = menu.itemClass().create( |
| 2115 | ['dddd','',function () { entryData = 'dddd'} ] |
| 2116 | ); |
| 2117 | menu.append(obj); |
| 2118 | expect(menu.limit(2).show(1)).toBe(true); |
| 2119 | expect(menu.shownItem(0).lcField()).toEqual(' a'); |
| 2120 | expect(menu.shownItem(1).lcField()).toEqual(' bb'); |
| 2121 | menu.next(); |
| 2122 | expect(menu.shownItem(1).lcField()).toEqual(' ccc'); |
| 2123 | menu.next(); |
| 2124 | expect(menu.shownItem(1).lcField()).toEqual(' dddd'); |
| 2125 | menu.next(); |
| 2126 | menu.next(); |
| 2127 | menu.next(); |
| 2128 | expect(menu.shownItem(0).lcField()).toEqual(' a'); |
| 2129 | expect(menu.lengthField().element().innerText).toEqual("a--bb--ccc--dddd--") |
| 2130 | expect(menu.slider().length()).toEqual(4); |
| 2131 | }); |
Leo Repp | 5bb710b | 2021-12-01 13:35:13 +0100 | [diff] [blame] | 2132 | |
| 2133 | it("should make the prefix active if nothing else can be", function () { |
| 2134 | |
| 2135 | var list = [ |
| 2136 | ["Constituency"], |
| 2137 | ["Lemma"], |
| 2138 | ["Morphology"], |
| 2139 | ["Part-of-Speech"], |
| 2140 | ["Syntax"] |
| 2141 | ]; |
| 2142 | |
| 2143 | var ExampleItemList2 = new Array; |
| 2144 | ExampleItemList2.push({defaultTextValue : "CIText1 "}); |
| 2145 | ExampleItemList2.push({}); |
| 2146 | |
| 2147 | var menu = OwnContainerMenu.create(list,ExampleItemList2); |
| 2148 | menu.container().addItem({ value : "Dynamically added", defaultTextValue : "dynamic"}) |
| 2149 | menu.limit(3).show(3); |
| 2150 | menu.focus(); //I don't know which of these above three lines are necessary for the error to occur, but at least one of them is. |
| 2151 | menu.container().add("a"); //These two simulate a keypress of a |
| 2152 | menu.show(); |
| 2153 | menu.container().add("s"); |
| 2154 | menu.show(); |
| 2155 | //item() gets the active item. |
| 2156 | expect(menu.container().item()).toEqual(menu.container()._cItemPrefix); |
| 2157 | }); |
| 2158 | |
| 2159 | it("removeItem and addItem should adjust storage of the currently active items position accordingly", function () { |
| 2160 | |
| 2161 | var list = [ |
| 2162 | ["Constituency"], |
| 2163 | ["Lemma"], |
| 2164 | ["Morphology"], |
| 2165 | ["Part-of-Speech"], |
| 2166 | ["Syntax"] |
| 2167 | ]; |
| 2168 | |
| 2169 | var ExampleItemList2 = new Array; |
| 2170 | ExampleItemList2.push({defaultTextValue : "CIText1 "}); |
| 2171 | ExampleItemList2.push({}); |
| 2172 | |
| 2173 | var menu = OwnContainerMenu.create(list,ExampleItemList2); |
| 2174 | menu.focus(); |
| 2175 | menu.show(); |
| 2176 | menu.container().add("s"); //make sure the prefix is selectable |
| 2177 | menu.show(); |
| 2178 | //item() gets the active item. |
| 2179 | menu.next();//Const |
| 2180 | menu.next();//Lemma |
| 2181 | menu.next();//Morph |
| 2182 | menu.next();//PoS |
| 2183 | menu.next();//Syn |
| 2184 | menu.next();//CIText1 |
| 2185 | menu.next();//"" |
| 2186 | menu.next();//Prefix |
| 2187 | //menu.container()._cItemPrefix.isPrefix=true; //For debugging the Spec |
| 2188 | expect(menu.container().item()).toEqual(menu.container()._cItemPrefix); |
| 2189 | menu.container().removeItemByIndex(0); |
| 2190 | expect(menu.container().item()).toEqual(menu.container()._cItemPrefix); |
| 2191 | expect(menu.container()._prefixPosition).toEqual(menu.container().items.indexOf(menu.container()._cItemPrefix)); |
| 2192 | menu.container().addItem({defaultTextValue:"Number 3"}); |
| 2193 | expect(menu.container().item()).toEqual(menu.container()._cItemPrefix); |
| 2194 | expect(menu.container()._prefixPosition).toEqual(menu.container().items.indexOf(menu.container()._cItemPrefix)); |
| 2195 | menu.prev();//make the new item active |
| 2196 | expect(menu.container().item()).toEqual(menu.container().item(menu.container().length()-2)); |
| 2197 | menu.container().removeItemByIndex(menu.container().length()-2); //remove the item we just added |
| 2198 | //As this should make the prefix active again. |
| 2199 | expect(menu.container().item()).toEqual(menu.container()._cItemPrefix); |
| 2200 | expect(menu.container()._prefixPosition).toEqual(menu.container().items.indexOf(menu.container()._cItemPrefix)); |
| 2201 | }); |
Leo Repp | 46903bf | 2021-12-18 16:05:53 +0100 | [diff] [blame] | 2202 | |
| 2203 | it('should highlight the prefix if no item matches.', function () { |
| 2204 | var menu = OwnContainerMenu.create(demolist,ExampleItemList); |
| 2205 | expect(menu.limit(3).show(3)).toBe(true); |
| 2206 | menu.element().focus(); |
| 2207 | |
| 2208 | emitKeyboardEvent(menu.element(), 'keypress', "E", 69); |
| 2209 | emitKeyboardEvent(menu.element(), 'keypress', "E", 69); |
| 2210 | emitKeyboardEvent(menu.element(), 'keypress', "E", 69); |
| 2211 | expect(menu.container()._cItemPrefix.active()).toBeTruthy(); |
| 2212 | expect(menu.prefix()).toEqual("EEE"); |
| 2213 | expect(menu.element().classList.contains("visible")).toBeTruthy(); |
| 2214 | expect(menu.container().element().classList.contains("visible")).toBeTruthy(); |
| 2215 | emitKeyboardEvent(menu.element(),'keydown'," ",13); |
| 2216 | //Should call reset() and hide() |
| 2217 | // hint containermenu should do something different. |
| 2218 | expect(menu.prefix()).toEqual("EEE"); |
| 2219 | expect(menu.element().classList.contains("visible")).toBeTruthy(); |
| 2220 | expect(menu.container().element().classList.contains("visible")).toBeTruthy(); |
| 2221 | }); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 2222 | }); |
Leo Repp | c66268e | 2021-10-28 11:44:35 +0200 | [diff] [blame] | 2223 | |
| 2224 | describe('KorAP.ContainerMenu.Container', function () { |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 2225 | it("should be initializable with no additional container items", function () { |
| 2226 | var list = [ |
| 2227 | ["Constituency"], |
| 2228 | ["Lemma"], |
| 2229 | ["Morphology"], |
| 2230 | ["Part-of-Speech"], |
| 2231 | ["Syntax"] |
| 2232 | ]; |
| 2233 | var menu = OwnContainerMenu.create(list); |
| 2234 | var container = menu.container(); |
| 2235 | expect(container._containerItemClass).toEqual(OwnContainerItemClass); |
| 2236 | expect(container.element().nodeName).toEqual("UL"); |
| 2237 | expect(container.element().classList.contains("menu")).toBeTruthy(); |
| 2238 | expect(container.element().classList.contains("visible")).toBeFalsy(); |
Leo Repp | 5799740 | 2021-08-18 16:37:52 +0200 | [diff] [blame] | 2239 | expect(menu._prefix).toEqual(container._cItemPrefix); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 2240 | expect(container.length()).toEqual(1); |
| 2241 | expect(container.length()).toEqual(container.items.length); |
| 2242 | expect(container.liveLength()).toEqual(0); |
Leo Repp | 5799740 | 2021-08-18 16:37:52 +0200 | [diff] [blame] | 2243 | expect(container.item(0)).toEqual(container._cItemPrefix); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 2244 | expect(container.active()).toBeFalsy(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 2245 | expect(directElementChildrenByTagName(menu.element(),"pref")).toEqual([]); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 2246 | expect(container.element().getElementsByClassName("pref").length).toEqual(1); |
| 2247 | |
| 2248 | |
| 2249 | |
| 2250 | menu.prefix("ad"); |
| 2251 | expect(container.liveLength()).toEqual(1); |
| 2252 | menu.prev(); |
| 2253 | expect(container.active()).toBeTruthy(); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 2254 | }); |
Leo Repp | 76ea813 | 2021-10-25 12:14:50 +0200 | [diff] [blame] | 2255 | it("should support dynamic adding of items", function () { |
| 2256 | |
| 2257 | var list = [ |
| 2258 | ["Constituency"], |
| 2259 | ["Lemma"], |
| 2260 | ["Morphology"], |
| 2261 | ["Part-of-Speech"], |
| 2262 | ["Syntax"] |
| 2263 | ]; |
| 2264 | |
| 2265 | var ExampleItemList2 = new Array; |
| 2266 | ExampleItemList2.push({defaultTextValue : "CIText1 "}); |
| 2267 | ExampleItemList2.push({}); |
| 2268 | |
| 2269 | var menu = OwnContainerMenu.create(list,ExampleItemList2); |
| 2270 | var container = menu.container(); |
| 2271 | expect(container.item(0).initContent().nodeValue).toEqual("CIText1 "); |
| 2272 | expect(container.item(1).initContent().nodeValue).toEqual(""); |
| 2273 | expect(container.item(2).initContent()).toEqual(undefined); |
| 2274 | expect(container.item(2)).toBeDefined(); |
| 2275 | expect(container._cItemPrefix.element().innerHTML).toEqual(""); |
| 2276 | container.addItem({defaultTextValue : "CIText2 "}); |
| 2277 | expect(container.item(0).initContent().nodeValue).toEqual("CIText1 "); |
| 2278 | expect(container.item(1).initContent().nodeValue).toEqual(""); |
| 2279 | expect(container.item(2).initContent().nodeValue).toEqual("CIText2 "); |
| 2280 | expect(container.item(3)).toBeDefined(); |
| 2281 | expect(container.item(3).initContent()).toEqual(undefined); |
| 2282 | expect(container._cItemPrefix.element().innerHTML).toEqual(""); |
| 2283 | container.add("a"); |
| 2284 | |
| 2285 | menu.next(); |
| 2286 | menu.next(); |
| 2287 | menu.next(); |
| 2288 | menu.next(); |
| 2289 | menu.next(); |
| 2290 | expect(container.item(0).active()).toBeTruthy(); |
| 2291 | menu.next(); |
| 2292 | expect(container.item(1).active()).toBeTruthy(); |
| 2293 | menu.next(); |
| 2294 | expect(container.item(2).active()).toBeTruthy(); |
| 2295 | menu.next(); |
| 2296 | expect(container.item(3).active()).toBeTruthy(); |
| 2297 | menu.next(); |
| 2298 | expect(container.item(3).active()).toBeFalsy(); |
| 2299 | menu.prev(); |
| 2300 | expect(container.item(3).active()).toBeTruthy(); |
| 2301 | menu.prev(); |
| 2302 | expect(container.item(2).active()).toBeTruthy(); |
| 2303 | menu.prev(); |
| 2304 | expect(container.item(1).active()).toBeTruthy(); |
| 2305 | menu.prev(); |
| 2306 | expect(container.item(0).active()).toBeTruthy(); |
| 2307 | menu.prev(); |
| 2308 | expect(container.item(0).active()).toBeFalsy(); |
| 2309 | |
| 2310 | |
| 2311 | |
| 2312 | }); |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 2313 | |
Leo Repp | 5799740 | 2021-08-18 16:37:52 +0200 | [diff] [blame] | 2314 | it("should support dynamic changing of text content", function () { |
| 2315 | var list = [ |
| 2316 | ["Constituency"], |
| 2317 | ["Lemma"], |
| 2318 | ["Morphology"], |
| 2319 | ["Part-of-Speech"], |
| 2320 | ["Syntax"] |
| 2321 | ]; |
| 2322 | |
| 2323 | var ExampleItemList2 = new Array; |
| 2324 | ExampleItemList2.push({defaultTextValue : "CIText1 "}); |
| 2325 | ExampleItemList2.push({}); |
| 2326 | |
| 2327 | var menu = OwnContainerMenu.create(list,ExampleItemList2); |
| 2328 | var container = menu.container(); |
Leo Repp | 8453916 | 2021-10-25 12:06:07 +0200 | [diff] [blame] | 2329 | expect(container.item(0).initContent().nodeValue).toEqual("CIText1 "); |
| 2330 | expect(container.item(1).initContent().nodeValue).toEqual(""); |
Leo Repp | 5799740 | 2021-08-18 16:37:52 +0200 | [diff] [blame] | 2331 | expect(container.item(2)).toBeDefined(); |
Leo Repp | 8453916 | 2021-10-25 12:06:07 +0200 | [diff] [blame] | 2332 | expect(container.item(2).initContent()).toEqual(undefined); |
Leo Repp | 5799740 | 2021-08-18 16:37:52 +0200 | [diff] [blame] | 2333 | expect(container._cItemPrefix.element().innerHTML).toEqual(""); |
Leo Repp | 8453916 | 2021-10-25 12:06:07 +0200 | [diff] [blame] | 2334 | expect(container.item(0).initContent("New1").nodeValue).toEqual("New1"); |
| 2335 | expect(container.item(1).initContent("New2").nodeValue).toEqual("New2"); |
Leo Repp | 5799740 | 2021-08-18 16:37:52 +0200 | [diff] [blame] | 2336 | expect(container._cItemPrefix.element().innerHTML).toEqual(""); |
| 2337 | expect(container.item(2)).toBeDefined(); |
Leo Repp | 8453916 | 2021-10-25 12:06:07 +0200 | [diff] [blame] | 2338 | expect(container.item(2).initContent()).toEqual(undefined); |
| 2339 | expect(container.item(0).initContent().nodeValue).toEqual("CIText1 "); |
| 2340 | expect(container.item(1).initContent().nodeValue).toEqual(""); |
Leo Repp | 5799740 | 2021-08-18 16:37:52 +0200 | [diff] [blame] | 2341 | expect(container._cItemPrefix.element().innerHTML).toEqual(""); |
| 2342 | expect(container.item(2)).toBeDefined(); |
Leo Repp | 8453916 | 2021-10-25 12:06:07 +0200 | [diff] [blame] | 2343 | expect(container.item(2).initContent()).toEqual(undefined); |
Leo Repp | 5799740 | 2021-08-18 16:37:52 +0200 | [diff] [blame] | 2344 | |
| 2345 | |
| 2346 | }); |
| 2347 | |
| 2348 | it("should support dynamic adding of items", function () { |
| 2349 | |
| 2350 | var list = [ |
| 2351 | ["Constituency"], |
| 2352 | ["Lemma"], |
| 2353 | ["Morphology"], |
| 2354 | ["Part-of-Speech"], |
| 2355 | ["Syntax"] |
| 2356 | ]; |
| 2357 | |
| 2358 | var ExampleItemList2 = new Array; |
| 2359 | ExampleItemList2.push({defaultTextValue : "CIText1 "}); |
| 2360 | ExampleItemList2.push({}); |
| 2361 | |
| 2362 | var menu = OwnContainerMenu.create(list,ExampleItemList2); |
| 2363 | var container = menu.container(); |
Leo Repp | 8453916 | 2021-10-25 12:06:07 +0200 | [diff] [blame] | 2364 | |
| 2365 | var testElement = container.element().children[0]; // Use this to test wether the HTML elements are in the correct order. |
| 2366 | |
| 2367 | expect(container.item(0).initContent().nodeValue).toEqual("CIText1 "); |
| 2368 | expect(testElement).toEqual(container.item(0).element()) |
| 2369 | |
| 2370 | testElement = testElement.nextElementSibling; |
| 2371 | expect(container.item(1).initContent().nodeValue).toEqual(""); |
| 2372 | expect(testElement).toEqual(container.item(1).element()) |
| 2373 | |
| 2374 | testElement = testElement.nextElementSibling; |
| 2375 | expect(container.item(2).initContent()).toEqual(undefined); |
Leo Repp | 5799740 | 2021-08-18 16:37:52 +0200 | [diff] [blame] | 2376 | expect(container.item(2)).toBeDefined(); |
Leo Repp | 8453916 | 2021-10-25 12:06:07 +0200 | [diff] [blame] | 2377 | expect(testElement).toEqual(container.item(2).element()) // = prefix |
Leo Repp | 5799740 | 2021-08-18 16:37:52 +0200 | [diff] [blame] | 2378 | expect(container._cItemPrefix.element().innerHTML).toEqual(""); |
Leo Repp | 8453916 | 2021-10-25 12:06:07 +0200 | [diff] [blame] | 2379 | expect(container.element().lastChild).toEqual(container._cItemPrefix.element()); |
| 2380 | |
Leo Repp | 5799740 | 2021-08-18 16:37:52 +0200 | [diff] [blame] | 2381 | container.addItem({defaultTextValue : "CIText2 "}); |
Leo Repp | 8453916 | 2021-10-25 12:06:07 +0200 | [diff] [blame] | 2382 | |
| 2383 | var testElement = container.element().children[0]; // Use this to test wether the HTML elements are in the correct order. |
| 2384 | |
| 2385 | expect(container.item(0).initContent().nodeValue).toEqual("CIText1 "); |
| 2386 | expect(testElement).toEqual(container.item(0).element()) |
| 2387 | |
| 2388 | testElement = testElement.nextElementSibling; |
| 2389 | expect(container.item(1).initContent().nodeValue).toEqual(""); |
| 2390 | expect(testElement).toEqual(container.item(1).element()) |
| 2391 | |
| 2392 | testElement = testElement.nextElementSibling; |
| 2393 | expect(container.item(2).initContent().nodeValue).toEqual("CIText2 "); |
| 2394 | expect(testElement).toEqual(container.item(2).element()) |
| 2395 | |
| 2396 | testElement = testElement.nextElementSibling; |
Leo Repp | 5799740 | 2021-08-18 16:37:52 +0200 | [diff] [blame] | 2397 | expect(container.item(3)).toBeDefined(); |
Leo Repp | 8453916 | 2021-10-25 12:06:07 +0200 | [diff] [blame] | 2398 | expect(container.item(3).initContent()).toEqual(undefined); |
| 2399 | expect(testElement).toEqual(container.item(3).element()) |
Leo Repp | 5799740 | 2021-08-18 16:37:52 +0200 | [diff] [blame] | 2400 | expect(container._cItemPrefix.element().innerHTML).toEqual(""); |
Leo Repp | 8453916 | 2021-10-25 12:06:07 +0200 | [diff] [blame] | 2401 | expect(container.element().lastChild).toEqual(container._cItemPrefix.element()); //Prefix must always be at the very back. |
| 2402 | |
Leo Repp | 5799740 | 2021-08-18 16:37:52 +0200 | [diff] [blame] | 2403 | container.add("a"); |
| 2404 | |
| 2405 | menu.next(); |
| 2406 | menu.next(); |
| 2407 | menu.next(); |
| 2408 | menu.next(); |
| 2409 | menu.next(); |
| 2410 | expect(container.item(0).active()).toBeTruthy(); |
| 2411 | menu.next(); |
| 2412 | expect(container.item(1).active()).toBeTruthy(); |
| 2413 | menu.next(); |
| 2414 | expect(container.item(2).active()).toBeTruthy(); |
| 2415 | menu.next(); |
| 2416 | expect(container.item(3).active()).toBeTruthy(); |
| 2417 | menu.next(); |
| 2418 | expect(container.item(3).active()).toBeFalsy(); |
| 2419 | menu.prev(); |
| 2420 | expect(container.item(3).active()).toBeTruthy(); |
| 2421 | menu.prev(); |
| 2422 | expect(container.item(2).active()).toBeTruthy(); |
| 2423 | menu.prev(); |
| 2424 | expect(container.item(1).active()).toBeTruthy(); |
| 2425 | menu.prev(); |
| 2426 | expect(container.item(0).active()).toBeTruthy(); |
| 2427 | menu.prev(); |
| 2428 | expect(container.item(0).active()).toBeFalsy(); |
| 2429 | |
| 2430 | |
| 2431 | |
| 2432 | }); |
| 2433 | |
Leo Repp | 5799740 | 2021-08-18 16:37:52 +0200 | [diff] [blame] | 2434 | |
Leo Repp | d162b2e | 2021-06-30 13:51:07 +0200 | [diff] [blame] | 2435 | }); |
| 2436 | }); |