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