Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1 | define( |
| 2 | ['alwaysmenu', 'menu/item', 'menu/prefix', 'menu/lengthField', 'alwaysentry'], |
| 3 | function (alwaysMenuClass, menuItemClass, prefixClass, lengthFieldClass, alwaysEntryClass) { |
| 4 | |
| 5 | //These class definitions were taken from menuSpec for a guideline on how to procede |
| 6 | |
| 7 | // The OwnAlwaysMenu item |
| 8 | const OwnAlwaysMenuItem = { |
| 9 | create : function (params) { |
| 10 | return Object.create(menuItemClass).upgradeTo(OwnAlwaysMenuItem)._init(params); |
| 11 | }, |
| 12 | content : function (content) { |
| 13 | if (arguments.length === 1) { |
| 14 | this._content = content; |
| 15 | }; |
| 16 | return this._content; |
| 17 | }, |
| 18 | _init : function (params) { |
| 19 | if (params[0] === undefined) |
| 20 | throw new Error("Missing parameters"); |
| 21 | |
| 22 | this._content = document.createTextNode(params[0]); |
| 23 | this._lcField = ' ' + this.content().textContent.toLowerCase(); |
| 24 | |
| 25 | return this; |
| 26 | } |
| 27 | }; |
| 28 | |
| 29 | // The OwnAlwaysMenu |
| 30 | let OwnAlwaysMenu = { |
| 31 | create : function (list) { |
| 32 | return alwaysMenuClass.create(list, { itemClass : OwnAlwaysMenuItem } ) |
| 33 | .upgradeTo(OwnAlwaysMenu); |
| 34 | } |
| 35 | }; |
| 36 | |
| 37 | |
| 38 | |
| 39 | // HintMenuItem |
| 40 | const HintMenuItem = { |
| 41 | create : function (params) { |
| 42 | return Object.create(menuItemClass) |
| 43 | .upgradeTo(HintMenuItem) |
| 44 | ._init(params); |
| 45 | }, |
| 46 | content : function (content) { |
| 47 | if (arguments.length === 1) { |
| 48 | this._content = content; |
| 49 | }; |
| 50 | return this._content; |
| 51 | }, |
| 52 | _init : function (params) { |
| 53 | if (params[0] === undefined || params[1] === undefined) |
| 54 | throw new Error("Missing parameters"); |
| 55 | |
| 56 | this._name = params[0]; |
| 57 | this._action = params[1]; |
| 58 | this._lcField = ' ' + this._name.toLowerCase(); |
| 59 | |
| 60 | if (params.length > 2) { |
| 61 | this._desc = params[2]; |
| 62 | this._lcField += " " + this._desc.toLowerCase(); |
| 63 | }; |
| 64 | |
| 65 | return this; |
| 66 | }, |
| 67 | |
| 68 | name : function () { |
| 69 | return this._name; |
| 70 | }, |
| 71 | action : function () { |
| 72 | return this._action; |
| 73 | }, |
| 74 | desc : function () { |
| 75 | return this._desc; |
| 76 | }, |
| 77 | element : function () { |
| 78 | // already defined |
| 79 | if (this._el !== undefined) |
| 80 | return this._el; |
| 81 | |
| 82 | // Create list item |
| 83 | var li = document.createElement("li"); |
| 84 | li.setAttribute("data-action", this._action); |
| 85 | |
| 86 | // Create title |
| 87 | var name = document.createElement("strong"); |
| 88 | name.appendChild(document.createTextNode(this._name)); |
| 89 | |
| 90 | li.appendChild(name); |
| 91 | |
| 92 | // Create description |
| 93 | if (this._desc !== undefined) { |
| 94 | var desc = document.createElement("span"); |
| 95 | desc.appendChild(document.createTextNode(this._desc)); |
| 96 | li.appendChild(desc); |
| 97 | }; |
| 98 | return this._el = li; |
| 99 | } |
| 100 | }; |
| 101 | |
| 102 | |
| 103 | // HintMenu |
| 104 | const HintMenu = { |
| 105 | create : function (context, list) { |
| 106 | var obj = alwaysMenuClass.create(list, {itemClass : HintMenuItem} ) |
| 107 | .upgradeTo(HintMenu); |
| 108 | obj._context = context; |
| 109 | return obj; |
| 110 | } |
| 111 | }; |
| 112 | |
| 113 | |
| 114 | // The ComplexMenuItem |
| 115 | const ComplexMenuItem = { |
| 116 | create : function (params) { |
| 117 | return Object.create(menuItemClass) |
| 118 | .upgradeTo(ComplexMenuItem) |
| 119 | ._init(params); |
| 120 | }, |
| 121 | content : function (content) { |
| 122 | if (arguments.length === 1) { |
| 123 | this._content = content; |
| 124 | }; |
| 125 | return this._content; |
| 126 | }, |
| 127 | _init : function (params) { |
| 128 | if (params[0] === undefined) |
| 129 | throw new Error("Missing parameters"); |
| 130 | |
| 131 | var r = document.createElement('div'); |
| 132 | for (var i = 1; i <= params.length; i++) { |
| 133 | var h = document.createElement('h' + i); |
| 134 | h.appendChild(document.createTextNode(params[i-1])); |
| 135 | r.appendChild(h); |
| 136 | }; |
| 137 | |
| 138 | this._content = r; |
| 139 | this._lcField = ' ' + this.content().textContent.toLowerCase(); |
| 140 | |
| 141 | return this; |
| 142 | } |
| 143 | }; |
| 144 | |
| 145 | |
| 146 | describe('KorAP.AlwaysMenu', function () { |
| 147 | var list = [ |
| 148 | ["Constituency", "c=", "Example 1"], |
| 149 | ["Lemma", "l="], |
| 150 | ["Morphology", "m=", "Example 2"], |
| 151 | ["Part-of-Speech", "p="], |
| 152 | ["Syntax", "syn="] |
| 153 | ]; |
| 154 | |
| 155 | var listMultiPrefix = [ |
| 156 | ["PP","PP ","Personal Pronoun"], |
| 157 | ["PPP","PPP ","Personal Pronoun, Plural"], |
| 158 | ["PPPA","PPPA ","Personal Pronoun, Plural, Acc."], |
| 159 | ["PPPD","PPPD ","Personal Pronoun, Plural, Dative"], |
| 160 | ["PPPR","PPPR ","Personal Pronoun, Plural, Direct"], |
| 161 | ["PPPO","PPPO ","Personal Pronoun, Plural, Oblique"], |
| 162 | ["PPS","PPS ","Personal Pronoun, Singular"], |
| 163 | ["PPSA","PPSA ","Personal Pronoun, Singular, Accusative"], |
| 164 | ["PPSD","PPSD ","Personal Pronoun, Singular, Dative"], |
| 165 | ["PPSR","PPSR ","Personal Pronoun, Singular, Direct"], |
| 166 | ["PPSN","PPSN ","Personal Pronoun, Singular, Nominative"], |
| 167 | ["PPSO","PPSO ","Personal Pronoun, Singular, Oblique"] |
| 168 | ]; |
| 169 | |
| 170 | var demolist = [ |
| 171 | ['Titel', 'title'], |
| 172 | ['Untertitel', 'subTitle'], |
| 173 | ['Veröffentlichungsdatum', 'pubDate'], |
| 174 | ['Länge', 'length'], |
| 175 | ['Autor', 'author'] |
| 176 | ]; |
| 177 | |
| 178 | var demolonglist = [ |
| 179 | ['Titel', 'title'], |
| 180 | ['Untertitel', 'subTitle'], |
| 181 | ['Veröffentlichungsdatum', 'pubDate'], |
| 182 | ['Länge', 'length'], |
| 183 | ['Autor', 'author'], |
| 184 | ['Genre', 'genre'], |
| 185 | ['corpusID', 'corpusID'], |
| 186 | ['docID', 'docID'], |
| 187 | ['textID', 'textID'], |
| 188 | ]; |
| 189 | |
| 190 | it('should be initializable', function () { |
| 191 | var list = [ |
| 192 | ["Constituency"], |
| 193 | ["Lemma"], |
| 194 | ["Morphology"], |
| 195 | ["Part-of-Speech"], |
| 196 | ["Syntax"] |
| 197 | ]; |
| 198 | |
| 199 | var menu = OwnAlwaysMenu.create(list); |
| 200 | menu._firstActive = true; |
| 201 | expect(menu.itemClass()).toEqual(OwnAlwaysMenuItem); |
| 202 | expect(menu._notItemElements).toEqual(4); |
marcrusian | 235a23a | 2021-05-26 14:28:11 +0200 | [diff] [blame] | 203 | expect(menu.element().getElementsByClassName("entry").length).toEqual(1); |
| 204 | expect(menu.element().getElementsByClassName("entry").length).toEqual(1); |
| 205 | expect(menu.element().getElementsByClassName("entry")[0].innerHTML).toEqual("Speichern"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 206 | expect(menu.alwaysEntry().element().innerHTML).toEqual("Speichern"); |
| 207 | //expect(menu.element().childNodes[3].innerHTML).toEqual("Speichern"); //? |
| 208 | // getElementsByClassName funktioniert bei allen Kindern. |
| 209 | |
| 210 | |
| 211 | // view |
| 212 | menu.show(); |
| 213 | |
| 214 | expect(menu.alwaysEntry().active()).toBe(false); |
| 215 | }); |
| 216 | |
| 217 | it('should be visible', function () { |
| 218 | var menu = HintMenu.create("cnx/", list); |
| 219 | expect(menu.removeItems()).toBe(undefined); |
| 220 | menu.limit(3); |
| 221 | |
| 222 | expect(menu.show()).toBe(true); |
| 223 | |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 224 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
| 225 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
| 226 | expect(directElementChildrenByTagName(menu.element(),"li")[1].getAttribute("data-action")).toEqual("l="); |
| 227 | expect(directElementChildrenByTagName(menu.element(),"li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 228 | expect(directElementChildrenByTagName(menu.element(),"li")[3]).toBe(undefined); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 229 | |
| 230 | // Check boundaries |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 231 | expect(directElementChildrenByTagName(menu.element(),"li")[0].classList.contains("no-more")).toBe(true); |
| 232 | expect(directElementChildrenByTagName(menu.element(),"li")[1].classList.contains("no-more")).toBe(false); |
| 233 | expect(directElementChildrenByTagName(menu.element(),"li")[2].classList.contains("no-more")).toBe(false); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 234 | }); |
| 235 | |
| 236 | it('should be filterable', function () { |
| 237 | var menu = HintMenu.create("cnx/", list); |
| 238 | menu.limit(3); |
| 239 | expect(menu.prefix("o").show()).toBe(true); |
| 240 | expect(menu.alwaysEntryValue("o").alwaysEntryValue()).toEqual("o"); |
| 241 | expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("o"); |
| 242 | expect(menu.alwaysEntry().element().innerHTML).toEqual("Speichern"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 243 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
| 244 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>"); |
| 245 | expect(directElementChildrenByTagName(menu.element(),"li")[2].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>"); |
| 246 | expect(directElementChildrenByTagName(menu.element(),"li")[3]).toBe(undefined); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 247 | |
| 248 | // Check boundaries |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 249 | expect(directElementChildrenByTagName(menu.element(),"li")[0].classList.contains("no-more")).toBe(true); |
| 250 | expect(directElementChildrenByTagName(menu.element(),"li")[1].classList.contains("no-more")).toBe(false); |
| 251 | expect(directElementChildrenByTagName(menu.element(),"li")[2].classList.contains("no-more")).toBe(true); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 252 | |
| 253 | menu.limit(2); |
| 254 | |
| 255 | expect(menu.prefix("o").show()).toBe(true); |
| 256 | expect(menu.alwaysEntryValue("o").alwaysEntryValue()).toEqual("o"); |
| 257 | expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("o"); |
| 258 | expect(menu.alwaysEntry().element().innerHTML).toEqual("Speichern"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 259 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
| 260 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>"); |
| 261 | expect(directElementChildrenByTagName(menu.element(),"li")[2]).toBe(undefined); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 262 | |
| 263 | // Check boundaries |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 264 | expect(directElementChildrenByTagName(menu.element(),"li")[0].classList.contains("no-more")).toBe(true); |
| 265 | expect(directElementChildrenByTagName(menu.element(),"li")[1].classList.contains("no-more")).toBe(false); |
| 266 | expect(directElementChildrenByTagName(menu.element(),"li")[2]).toBe(undefined); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 267 | |
| 268 | expect(menu.prefix("e").show()).toBe(true); |
| 269 | expect(menu.alwaysEntryValue("e").alwaysEntryValue()).toEqual("e"); |
| 270 | expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("e"); |
| 271 | expect(menu.alwaysEntry().element().innerHTML).toEqual("Speichern"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 272 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
| 273 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
| 274 | expect(directElementChildrenByTagName(menu.element(),"li")[2]).toBe(undefined); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 275 | |
| 276 | menu.limit(5); |
| 277 | expect(menu.prefix("a").show()).toBe(true); |
| 278 | expect(menu.alwaysEntryValue("a").alwaysEntryValue()).toEqual("a"); |
| 279 | expect(menu.element().getElementsByClassName("pref")[0].innerHTML).toEqual("a"); |
| 280 | expect(menu.alwaysEntry().element().innerHTML).toEqual("Speichern"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 281 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Ex<mark>a</mark>mple 1</span>"); |
| 282 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Lemm<mark>a</mark></strong>"); |
| 283 | expect(directElementChildrenByTagName(menu.element(),"li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Ex<mark>a</mark>mple 2</span>"); |
| 284 | expect(directElementChildrenByTagName(menu.element(),"li")[3].innerHTML).toEqual("<strong>P<mark>a</mark>rt-of-Speech</strong>"); |
| 285 | expect(directElementChildrenByTagName(menu.element(),"li")[4].innerHTML).toEqual("<strong>Synt<mark>a</mark>x</strong>"); |
| 286 | expect(directElementChildrenByTagName(menu.element(),"li")[5]).toBe(undefined); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 287 | }); |
| 288 | |
| 289 | |
| 290 | it('should be nextable', function () { |
| 291 | var menu = HintMenu.create("cnx/", list); |
| 292 | menu._firstActive = true; |
| 293 | |
| 294 | expect(menu._prefix.active()).toBe(false); |
| 295 | |
| 296 | // Show only 3 items |
| 297 | menu.limit(3); |
| 298 | expect(menu.show()).toBe(true); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 299 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 300 | expect(menu.shownItem(0).active()).toBe(true); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 301 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 302 | expect(menu.shownItem(1).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 303 | expect(directElementChildrenByTagName(menu.element(),"li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 304 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 305 | expect(directElementChildrenByTagName(menu.element(),"li")[3]).toBe(undefined); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 306 | expect(menu.alwaysEntry().active()).toBe(false); |
| 307 | |
| 308 | // Activate next (1) |
| 309 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 310 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 311 | expect(menu.shownItem(0).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 312 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 313 | expect(menu.shownItem(1).active()).toBe(true); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 314 | expect(directElementChildrenByTagName(menu.element(),"li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 315 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 316 | expect(directElementChildrenByTagName(menu.element(),"li")[3]).toBe(undefined); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 317 | expect(menu.alwaysEntry().active()).toBe(false); |
| 318 | |
| 319 | // Activate next (2) |
| 320 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 321 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 322 | expect(menu.shownItem(0).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 323 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 324 | expect(menu.shownItem(1).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 325 | expect(directElementChildrenByTagName(menu.element(),"li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 326 | expect(menu.shownItem(2).active()).toBe(true); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 327 | expect(directElementChildrenByTagName(menu.element(),"li")[3]).toBe(undefined); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 328 | expect(menu.alwaysEntry().active()).toBe(false); |
| 329 | |
| 330 | // Activate next (3) |
| 331 | // scroll! |
| 332 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 333 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Lemma</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 334 | expect(menu.shownItem(0).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 335 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 336 | expect(menu.shownItem(1).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 337 | expect(directElementChildrenByTagName(menu.element(),"li")[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 338 | expect(menu.shownItem(2).active()).toBe(true); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 339 | expect(directElementChildrenByTagName(menu.element(),"li")[3]).toBe(undefined); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 340 | expect(menu.alwaysEntry().active()).toBe(false); |
| 341 | |
| 342 | // Activate next (4) |
| 343 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 344 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 345 | expect(menu.shownItem(0).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 346 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 347 | expect(menu.shownItem(1).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 348 | expect(directElementChildrenByTagName(menu.element(),"li")[2].innerHTML).toEqual("<strong>Syntax</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 349 | expect(menu.shownItem(2).active()).toBe(true); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 350 | expect(directElementChildrenByTagName(menu.element(),"li")[3]).toBe(undefined); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 351 | expect(menu.alwaysEntry().active()).toBe(false); |
| 352 | |
| 353 | // Activate next (5) - Entry / Speichern |
| 354 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 355 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 356 | expect(menu.shownItem(0).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 357 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 358 | expect(menu.shownItem(1).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 359 | expect(directElementChildrenByTagName(menu.element(),"li")[2].innerHTML).toEqual("<strong>Syntax</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 360 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 361 | expect(directElementChildrenByTagName(menu.element(),"li")[3]).toBe(undefined); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 362 | expect(menu.alwaysEntry().active()).toBe(true); |
| 363 | |
| 364 | // Activate next (6) - ROLL |
| 365 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 366 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 367 | expect(menu.shownItem(0).active()).toBe(true); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 368 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 369 | expect(menu.shownItem(1).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 370 | expect(directElementChildrenByTagName(menu.element(),"li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 371 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 372 | expect(directElementChildrenByTagName(menu.element(),"li")[3]).toBe(undefined); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 373 | expect(menu.alwaysEntry().active()).toBe(false); |
| 374 | |
| 375 | // Active next (7) |
| 376 | menu.next(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 377 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 378 | expect(menu.shownItem(0).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 379 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 380 | expect(menu.shownItem(1).active()).toBe(true); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 381 | expect(directElementChildrenByTagName(menu.element(),"li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 382 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 383 | expect(directElementChildrenByTagName(menu.element(),"li")[3]).toBe(undefined); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 384 | expect(menu.alwaysEntry().active()).toBe(false); |
| 385 | |
| 386 | expect(menu._prefix.active()).toBe(false); |
| 387 | }); |
| 388 | |
| 389 | it('should be nextable without active field', function () { |
| 390 | var menu = HintMenu.create("cnx/", list); |
| 391 | menu.limit(3); |
| 392 | expect(menu.show()).toBe(true); |
| 393 | menu.next(); |
| 394 | expect(menu.shownItem(0).active()).toEqual(true); |
| 395 | }); |
| 396 | |
| 397 | |
| 398 | it('should be prevable', function () { |
| 399 | var menu = HintMenu.create("cnx/", list); |
| 400 | menu._firstActive = true; |
| 401 | menu.limit(3); |
| 402 | expect(menu.show()).toBe(true); |
| 403 | expect(menu._prefix.active()).toBe(false); |
| 404 | expect(menu.alwaysEntryValue()).toBe(""); |
| 405 | |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 406 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 407 | expect(menu.shownItem(0).active()).toBe(true); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 408 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 409 | expect(menu.shownItem(1).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 410 | expect(directElementChildrenByTagName(menu.element(),"li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 411 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 412 | expect(directElementChildrenByTagName(menu.element(),"li")[3]).toBe(undefined); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 413 | expect(menu.alwaysEntry().active()).toBe(false); |
| 414 | |
| 415 | |
| 416 | // Activate prev (1) - roll to bottom |
| 417 | menu.prev(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 418 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 419 | expect(menu.shownItem(0).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 420 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 421 | expect(menu.shownItem(1).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 422 | expect(directElementChildrenByTagName(menu.element(),"li")[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 423 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 424 | expect(directElementChildrenByTagName(menu.element(),"li")[3]).toBe(undefined); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 425 | expect(menu.alwaysEntry().active()).toBe(true); |
| 426 | |
| 427 | // Activate prev (2) |
| 428 | menu.prev(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 429 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 430 | expect(menu.shownItem(0).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 431 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 432 | expect(menu.shownItem(1).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 433 | expect(directElementChildrenByTagName(menu.element(),"li")[2].innerHTML).toEqual("<strong>Syntax</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 434 | expect(menu.shownItem(2).active()).toBe(true); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 435 | expect(directElementChildrenByTagName(menu.element(),"li")[3]).toBe(undefined); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 436 | expect(menu.alwaysEntry().active()).toBe(false); |
| 437 | |
| 438 | // Activate prev (3) |
| 439 | menu.prev(); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 440 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 441 | expect(menu.shownItem(0).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 442 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 443 | expect(menu.shownItem(1).active()).toBe(true); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 444 | expect(directElementChildrenByTagName(menu.element(),"li")[2].innerHTML).toEqual("<strong>Syntax</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 445 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 446 | expect(directElementChildrenByTagName(menu.element(),"li")[3]).toBe(undefined); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 447 | expect(menu.alwaysEntry().active()).toBe(false); |
| 448 | |
| 449 | // Activate prev (4) |
| 450 | menu.prev(); |
| 451 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
| 452 | expect(menu.shownItem(0).active()).toBe(true); |
| 453 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
| 454 | expect(menu.shownItem(1).active()).toBe(false); |
| 455 | expect(menu.shownItem(2).name()).toEqual("Syntax"); |
| 456 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 457 | expect(directElementChildrenByTagName(menu.element(),"li")[3]).toBe(undefined); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 458 | expect(menu.alwaysEntry().active()).toBe(false); |
| 459 | |
| 460 | // Activate prev (5) |
| 461 | menu.prev(); |
| 462 | expect(menu.shownItem(0).name()).toEqual("Lemma"); |
| 463 | expect(menu.shownItem(0).active()).toBe(true); |
| 464 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
| 465 | expect(menu.shownItem(1).active()).toBe(false); |
| 466 | expect(menu.shownItem(2).name()).toEqual("Part-of-Speech"); |
| 467 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 468 | expect(directElementChildrenByTagName(menu.element(),"li")[3]).toBe(undefined); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 469 | expect(menu.alwaysEntry().active()).toBe(false); |
| 470 | |
| 471 | // Activate prev (6) |
| 472 | menu.prev(); |
| 473 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
| 474 | expect(menu.shownItem(0).active()).toBe(true); |
| 475 | expect(menu.shownItem(1).name()).toEqual("Lemma"); |
| 476 | expect(menu.shownItem(1).active()).toBe(false); |
| 477 | expect(menu.shownItem(2).name()).toEqual("Morphology"); |
| 478 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 479 | expect(directElementChildrenByTagName(menu.element(),"li")[3]).toBe(undefined); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 480 | expect(menu.alwaysEntry().active()).toBe(false); |
| 481 | |
| 482 | // Activate next (7) |
| 483 | menu.next(); |
| 484 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
| 485 | expect(menu.shownItem(0).active()).toBe(false); |
| 486 | expect(menu.shownItem(1).name()).toEqual("Lemma"); |
| 487 | expect(menu.shownItem(1).active()).toBe(true); |
| 488 | expect(menu.shownItem(2).name()).toEqual("Morphology"); |
| 489 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 490 | expect(directElementChildrenByTagName(menu.element(),"li")[3]).toBe(undefined); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 491 | expect(menu.alwaysEntry().active()).toBe(false); |
| 492 | |
| 493 | // Activate prev (8) |
| 494 | menu.prev(); |
| 495 | |
| 496 | // Activate prev (9) - Roll again |
| 497 | menu.prev(); |
| 498 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
| 499 | expect(menu.shownItem(0).active()).toBe(false); |
| 500 | expect(menu.shownItem(1).name()).toEqual("Lemma"); |
| 501 | expect(menu.shownItem(1).active()).toBe(false); |
| 502 | expect(menu.shownItem(2).name()).toEqual("Morphology"); |
| 503 | expect(menu.shownItem(2).active()).toBe(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 504 | expect(directElementChildrenByTagName(menu.element(),"li")[3]).toBe(undefined); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 505 | expect(menu.alwaysEntry().active()).toBe(true); |
| 506 | |
| 507 | // Activate prev (10) |
| 508 | menu.prev() |
| 509 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
| 510 | expect(menu.shownItem(0).active()).toBe(false); |
| 511 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
| 512 | expect(menu.shownItem(1).active()).toBe(false); |
| 513 | expect(menu.shownItem(2).name()).toEqual("Syntax"); |
| 514 | expect(menu.shownItem(2).active()).toBe(true); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 515 | expect(directElementChildrenByTagName(menu.element(),"li")[3]).toBe(undefined); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 516 | expect(menu.alwaysEntry().active()).toBe(false); |
| 517 | expect(menu._prefix.active()).toBe(false); |
| 518 | expect(menu.alwaysEntryValue()).toBe(""); |
| 519 | expect(menu.alwaysEntry().element().innerHTML).toBe("Speichern"); |
| 520 | |
| 521 | }); |
| 522 | |
| 523 | it('should be prevable without active field', function () { |
| 524 | var menu = HintMenu.create("cnx/", list); |
| 525 | menu.limit(3); |
| 526 | expect(menu.show()).toBe(true); |
| 527 | menu.prev(); |
| 528 | expect(menu.alwaysEntry().active()).toBe(true); |
| 529 | expect(menu.shownItem(2).active()).toEqual(false); |
| 530 | expect(menu.shownItem(2).lcField()).toEqual(' morphology example 2'); |
| 531 | menu.prev() |
| 532 | expect(menu.shownItem(2).active()).toEqual(true); |
| 533 | expect(menu.shownItem(2).lcField()).toEqual(' syntax'); |
| 534 | }); |
| 535 | |
| 536 | it('should be navigatable and filterable (prefix = "o")', function () { |
| 537 | var menu = HintMenu.create("cnx/", list); |
| 538 | menu._firstActive = true; |
| 539 | menu.limit(2); |
| 540 | |
| 541 | expect(menu.prefix("o").show()).toBe(true); |
| 542 | expect(menu.alwaysEntryValue("o").alwaysEntryValue()).toBe("o"); |
| 543 | expect(menu._prefix.active()).toBe(false); |
| 544 | expect(menu.alwaysEntry().active()).toBe(false); |
| 545 | |
| 546 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 547 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 548 | expect(menu.shownItem(0).active()).toBe(true); |
| 549 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 550 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 551 | expect(menu.shownItem(1).active()).toBe(false); |
| 552 | expect(menu.shownItem(2)).toBe(undefined); |
| 553 | |
| 554 | // Next (1) |
| 555 | menu.next(); |
| 556 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 557 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 558 | expect(menu.shownItem(0).active()).toBe(false); |
| 559 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 560 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 561 | expect(menu.shownItem(1).active()).toBe(true); |
| 562 | expect(menu.shownItem(2)).toBe(undefined); |
| 563 | |
| 564 | // Next (2) |
| 565 | menu.next(); |
| 566 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 567 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 568 | expect(menu.shownItem(0).active()).toBe(false); |
| 569 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 570 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 571 | expect(menu.shownItem(1).active()).toBe(true); |
| 572 | expect(menu.shownItem(2)).toBe(undefined); |
| 573 | |
| 574 | // Next (3) - to prefix |
| 575 | menu.next(); |
| 576 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 577 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 578 | expect(menu.shownItem(0).active()).toBe(false); |
| 579 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 580 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 581 | expect(menu.shownItem(1).active()).toBe(false); |
| 582 | expect(menu.shownItem(2)).toBe(undefined); |
| 583 | expect(menu._prefix.active()).toBe(true); |
| 584 | expect(menu.alwaysEntry().active()).toBe(false); |
| 585 | |
| 586 | // Next (4) - to entry |
| 587 | menu.next(); |
| 588 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 589 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 590 | expect(menu.shownItem(0).active()).toBe(false); |
| 591 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 592 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 593 | expect(menu.shownItem(1).active()).toBe(false); |
| 594 | expect(menu.shownItem(2)).toBe(undefined); |
| 595 | expect(menu._prefix.active()).toBe(false); |
| 596 | expect(menu.alwaysEntry().active()).toBe(true); |
| 597 | |
| 598 | menu.next(); |
| 599 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 600 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 601 | expect(menu.shownItem(0).active()).toBe(true); |
| 602 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 603 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 604 | expect(menu.shownItem(1).active()).toBe(false); |
| 605 | expect(menu.shownItem(2)).toBe(undefined); |
| 606 | |
| 607 | expect(menu.prefix("o").show()).toBe(true); |
| 608 | expect(menu.alwaysEntryValue("o").alwaysEntryValue()).toBe("o"); |
| 609 | expect(menu._prefix.active()).toBe(false); |
| 610 | expect(menu.alwaysEntry().active()).toBe(false); |
| 611 | }); |
| 612 | |
| 613 | |
| 614 | it('should be navigatable and filterable (prefix = "ex", "e")', function () { |
| 615 | var menu = HintMenu.create("cnx/", list); |
| 616 | menu._firstActive = true; |
| 617 | |
| 618 | menu.limit(2); |
| 619 | expect(menu.prefix("ex").show()).toBe(true); |
| 620 | expect(menu.alwaysEntryValue("ex").alwaysEntryValue()).toBe("ex"); |
| 621 | expect(menu._prefix.active()).toBe(false); |
| 622 | expect(menu.alwaysEntry().active()).toBe(false); |
| 623 | |
| 624 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 625 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 626 | expect(menu.shownItem(0).active()).toBe(true); |
| 627 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 628 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 629 | expect(menu.shownItem(1).active()).toBe(false); |
| 630 | expect(menu.shownItem(2)).toBe(undefined); |
| 631 | |
| 632 | // Next (1) |
| 633 | menu.next(); |
| 634 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 635 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 636 | expect(menu.shownItem(0).active()).toBe(false); |
| 637 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 638 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 639 | expect(menu.shownItem(1).active()).toBe(true); |
| 640 | expect(menu.shownItem(2)).toBe(undefined); |
| 641 | expect(menu.alwaysEntryValue()).toBe("ex"); |
| 642 | expect(menu._prefix.active()).toBe(false); |
| 643 | expect(menu.alwaysEntry().active()).toBe(false); |
| 644 | |
| 645 | // Next (2) |
| 646 | menu.next(); |
| 647 | |
| 648 | expect(menu.prefix()).toEqual('ex'); |
| 649 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 650 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 651 | expect(menu.shownItem(0).active()).toBe(false); |
| 652 | |
| 653 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 654 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 655 | expect(menu.shownItem(1).active()).toBe(false); |
| 656 | expect(menu.shownItem(2)).toBe(undefined); |
| 657 | expect(menu.alwaysEntryValue()).toBe("ex"); |
| 658 | expect(menu._prefix.active()).toBe(true); |
| 659 | expect(menu.alwaysEntry().active()).toBe(false); |
| 660 | |
| 661 | // Reset limit |
| 662 | menu.limit(5); |
| 663 | |
| 664 | // Change show |
| 665 | expect(menu.prefix("e").show()).toBe(true); |
| 666 | expect(menu.alwaysEntryValue("e").alwaysEntryValue()).toBe("e"); |
| 667 | expect(menu._prefix.active()).toBe(false); |
| 668 | expect(menu.alwaysEntry().active()).toBe(false); |
| 669 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 670 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 671 | expect(menu.shownItem(0).active()).toBe(true); |
| 672 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 673 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 674 | expect(menu.shownItem(1).active()).toBe(false); |
| 675 | expect(menu.shownItem(2)).toBe(undefined); |
| 676 | |
| 677 | // Next (1) |
| 678 | menu.next(); |
| 679 | expect(menu._prefix.active()).toBe(false); |
| 680 | expect(menu.prefix()).toEqual('e'); |
| 681 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 682 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 683 | expect(menu.shownItem(0).active()).toBe(false); |
| 684 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 685 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 686 | expect(menu.shownItem(1).active()).toBe(true); |
| 687 | expect(menu.shownItem(2)).toBe(undefined); |
| 688 | expect(menu._prefix.active()).toBe(false); |
| 689 | expect(menu.alwaysEntry().active()).toBe(false); |
| 690 | |
| 691 | // Next (2) |
| 692 | menu.next(); |
| 693 | expect(menu._prefix.active()).toBe(true); |
| 694 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 695 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 696 | expect(menu.shownItem(0).active()).toBe(false); |
| 697 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 698 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 699 | expect(menu.shownItem(1).active()).toBe(false); |
| 700 | expect(menu.shownItem(2)).toBe(undefined); |
| 701 | expect(menu._prefix.active()).toBe(true); |
| 702 | expect(menu.alwaysEntry().active()).toBe(false); |
| 703 | |
| 704 | // Next (2.5) |
| 705 | menu.next(); |
| 706 | expect(menu._prefix.active()).toBe(false); |
| 707 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 708 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 709 | expect(menu.shownItem(0).active()).toBe(false); |
| 710 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 711 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 712 | expect(menu.shownItem(1).active()).toBe(false); |
| 713 | expect(menu.shownItem(2)).toBe(undefined); |
| 714 | expect(menu._prefix.active()).toBe(false); |
| 715 | expect(menu.alwaysEntry().active()).toBe(true); |
| 716 | |
| 717 | // Next (3) |
| 718 | menu.next(); |
| 719 | expect(menu._prefix.active()).toBe(false); |
| 720 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 721 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 722 | expect(menu.shownItem(0).active()).toBe(true); |
| 723 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 724 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 725 | expect(menu.shownItem(1).active()).toBe(false); |
| 726 | expect(menu.shownItem(2)).toBe(undefined); |
| 727 | |
| 728 | expect(menu.alwaysEntryValue()).toBe("e"); |
| 729 | expect(menu._prefix.active()).toBe(false); |
| 730 | expect(menu.alwaysEntry().active()).toBe(false); |
| 731 | }); |
| 732 | |
| 733 | it('should be filterable (multiple prefix = "pro sin")', function () { |
| 734 | var menu = HintMenu.create("drukola/p=", listMultiPrefix); |
| 735 | menu._firstActive = true; |
| 736 | |
| 737 | menu.limit(2); |
| 738 | expect(menu.prefix("pro sin").show()).toBe(true); |
| 739 | expect(menu.alwaysEntryValue("pro sin").alwaysEntryValue()).toBe("pro sin"); |
| 740 | expect(menu._prefix.active()).toBe(false); |
| 741 | expect(menu.alwaysEntry().active()).toBe(false); |
| 742 | expect(menu.shownItem(0).name()).toEqual("PPS"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 743 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual( |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 744 | "<strong>PPS</strong><span>Personal <mark>Pro</mark>noun, <mark>Sin</mark>gular</span>" |
| 745 | ); |
| 746 | |
| 747 | expect(menu.shownItem(0).active()).toBe(true); |
| 748 | expect(menu.shownItem(1).name()).toEqual("PPSA"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 749 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>PPSA</strong><span>Personal <mark>Pro</mark>noun, <mark>Sin</mark>gular, Accusative</span>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 750 | expect(menu.shownItem(1).active()).toBe(false); |
| 751 | |
| 752 | expect(menu.shownItem(2)).toBe(undefined); |
| 753 | }); |
| 754 | |
| 755 | it('should be filterable (trimming = " p")', function () { |
| 756 | var menu = HintMenu.create("/p=", listMultiPrefix); |
| 757 | // menu._firstActive = true; |
| 758 | |
| 759 | menu.limit(2); |
| 760 | expect(menu.show()).toBe(true); |
| 761 | menu._prefix.add(" "); |
| 762 | menu._entry.add(" ") |
| 763 | expect(menu.show()).toBe(true); |
| 764 | menu._prefix.add("p") |
| 765 | menu._entry.add("p") |
| 766 | expect(menu.alwaysEntryValue()).toBe(" p"); |
| 767 | expect(menu.show()).toBe(true); |
| 768 | expect(menu.shownItem(0).name()).toEqual("PP"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 769 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual( |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 770 | "<strong><mark>P</mark><mark>P</mark></strong>"+ |
| 771 | "<span><mark>P</mark>ersonal <mark>P</mark>ronoun</span>" |
| 772 | ); |
| 773 | }); |
| 774 | |
| 775 | |
| 776 | |
| 777 | it('should ignore navigation with failing prefix', function () { |
| 778 | var menu = HintMenu.create("cnx/", list); |
| 779 | menu.limit(2); |
| 780 | expect(menu.show()).toBe(true); |
| 781 | |
| 782 | menu.next(); |
| 783 | |
| 784 | expect(menu.prefix("exit").show()).toBe(true); |
| 785 | expect(menu.element().querySelector('li')).toBe(null); |
| 786 | expect(menu.shownItem(0)).toBeUndefined(); |
| 787 | expect(menu._prefix.active()).toBe(true); |
| 788 | |
| 789 | menu.next(); |
| 790 | expect(menu._prefix.active()).toBe(false); |
| 791 | expect(menu._entry.active()).toBe(true); |
| 792 | |
| 793 | menu.next(); |
| 794 | expect(menu._prefix.active()).toBe(true); |
| 795 | expect(menu._entry.active()).toBe(false); |
| 796 | |
| 797 | menu.prev(); |
| 798 | expect(menu._prefix.active()).toBe(false); |
| 799 | expect(menu._entry.active()).toBe(true); |
| 800 | |
| 801 | menu.prev(); |
| 802 | expect(menu._prefix.active()).toBe(true); |
| 803 | expect(menu._entry.active()).toBe(false); |
| 804 | |
| 805 | }); |
| 806 | |
| 807 | it('should be navigatable with prefix', function () { |
| 808 | var menu = HintMenu.create("cnx/", demolist); |
| 809 | menu._firstActive = true; |
| 810 | |
| 811 | menu.limit(3); |
| 812 | |
| 813 | expect(menu.show()).toBe(true); |
| 814 | expect(menu.prefix()).toEqual(""); |
| 815 | expect(menu.alwaysEntryValue()).toEqual(""); |
| 816 | expect(menu._prefix.active()).toEqual(false); |
| 817 | expect(menu._entry.active()).toEqual(false); |
| 818 | |
| 819 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 820 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Titel</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 821 | expect(menu.shownItem(0).active()).toBe(true); |
| 822 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 823 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 824 | expect(menu.shownItem(1).active()).toBe(false); |
| 825 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 826 | expect(directElementChildrenByTagName(menu.element(),"li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 827 | expect(menu.shownItem(2).active()).toBe(false); |
| 828 | expect(menu.shownItem(3)).toBe(undefined); |
| 829 | expect(menu._prefix.active()).toEqual(false); |
| 830 | expect(menu._entry.active()).toEqual(false); |
| 831 | |
| 832 | menu._prefix.add('a'); |
| 833 | menu._entry.add('a'); |
| 834 | expect(menu._prefix.active()).toEqual(false); |
| 835 | expect(menu._entry.active()).toEqual(false); |
| 836 | expect(menu.show()).toBe(true); |
| 837 | expect(menu.prefix()).toEqual("a"); |
| 838 | expect(menu.alwaysEntryValue()).toEqual("a"); |
| 839 | expect(menu.shownItem(0).name()).toEqual("Autor"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 840 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 841 | |
| 842 | menu._prefix.add('u'); |
| 843 | menu._entry.add('u'); |
| 844 | expect(menu.show()).toBe(true); |
| 845 | expect(menu.prefix()).toEqual("au"); |
| 846 | expect(menu.alwaysEntryValue()).toEqual("au"); |
| 847 | expect(menu.shownItem(0).name()).toEqual("Autor"); |
| 848 | expect(menu._prefix.active()).toEqual(false); |
| 849 | expect(menu._entry.active()).toEqual(false); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 850 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong><mark>Au</mark>tor</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 851 | |
| 852 | menu._prefix.chop(); |
| 853 | menu._entry.chop(); |
| 854 | expect(menu.show()).toBe(true); |
| 855 | expect(menu.prefix()).toEqual("a"); |
| 856 | expect(menu.alwaysEntryValue()).toEqual("a"); |
| 857 | expect(menu.shownItem(0).name()).toEqual("Autor"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 858 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 859 | |
| 860 | menu._prefix.chop(); |
| 861 | menu._entry.chop(); |
| 862 | expect(menu.show()).toBe(true); |
| 863 | expect(menu.prefix()).toEqual(""); |
| 864 | expect(menu.alwaysEntryValue()).toEqual(""); |
| 865 | expect(menu._prefix.active()).toEqual(false); |
| 866 | expect(menu._entry.active()).toEqual(false); |
| 867 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 868 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Titel</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 869 | expect(menu.shownItem(0).active()).toBe(true); |
| 870 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 871 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 872 | expect(menu.shownItem(1).active()).toBe(false); |
| 873 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 874 | expect(directElementChildrenByTagName(menu.element(),"li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 875 | expect(menu.shownItem(2).active()).toBe(false); |
| 876 | expect(menu.shownItem(3)).toBe(undefined); |
| 877 | |
| 878 | // Forward |
| 879 | menu._prefix.chop(); |
| 880 | menu._entry.chop(); |
| 881 | expect(menu.show()).toBe(true); |
| 882 | expect(menu.prefix()).toEqual(""); |
| 883 | expect(menu._prefix.active()).toEqual(false); |
| 884 | expect(menu._entry.active()).toEqual(false); |
| 885 | expect(menu.alwaysEntryValue()).toEqual(""); |
| 886 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 887 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Titel</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 888 | expect(menu.shownItem(0).active()).toBe(true); |
| 889 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 890 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 891 | expect(menu.shownItem(1).active()).toBe(false); |
| 892 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 893 | expect(directElementChildrenByTagName(menu.element(),"li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 894 | expect(menu.shownItem(2).active()).toBe(false); |
| 895 | |
| 896 | // Forward |
| 897 | menu.next(); |
| 898 | expect(menu.prefix()).toEqual(""); |
| 899 | expect(menu.alwaysEntryValue()).toEqual(""); |
| 900 | expect(menu._prefix.active()).toEqual(false); |
| 901 | expect(menu._entry.active()).toEqual(false); |
| 902 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 903 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Titel</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 904 | expect(menu.shownItem(0).active()).toBe(false); |
| 905 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 906 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 907 | expect(menu.shownItem(1).active()).toBe(true); |
| 908 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 909 | expect(directElementChildrenByTagName(menu.element(),"li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 910 | expect(menu.shownItem(2).active()).toBe(false); |
| 911 | expect(menu.shownItem(3)).toBe(undefined); |
| 912 | |
| 913 | // Forward |
| 914 | menu.next(); |
| 915 | expect(menu.prefix()).toEqual(""); |
| 916 | expect(menu.alwaysEntryValue()).toEqual(""); |
| 917 | expect(menu._prefix.active()).toEqual(false); |
| 918 | expect(menu._entry.active()).toEqual(false); |
| 919 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 920 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Titel</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 921 | expect(menu.shownItem(0).active()).toBe(false); |
| 922 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 923 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 924 | expect(menu.shownItem(1).active()).toBe(false); |
| 925 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 926 | expect(directElementChildrenByTagName(menu.element(),"li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 927 | expect(menu.shownItem(2).active()).toBe(true); |
| 928 | expect(menu.shownItem(3)).toBe(undefined); |
| 929 | |
| 930 | // Forward |
| 931 | menu.next(); |
| 932 | expect(menu.prefix()).toEqual(""); |
| 933 | expect(menu.alwaysEntryValue()).toEqual(""); |
| 934 | expect(menu.shownItem(0).name()).toEqual("Untertitel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 935 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 936 | expect(menu.shownItem(0).active()).toBe(false); |
| 937 | expect(menu.shownItem(1).name()).toEqual("Veröffentlichungsdatum"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 938 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 939 | expect(menu.shownItem(1).active()).toBe(false); |
| 940 | expect(menu.shownItem(2).name()).toEqual("Länge"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 941 | expect(directElementChildrenByTagName(menu.element(),"li")[2].innerHTML).toEqual("<strong>Länge</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 942 | expect(menu.shownItem(2).active()).toBe(true); |
| 943 | expect(menu.shownItem(3)).toBe(undefined); |
| 944 | expect(menu._prefix.active()).toEqual(false); |
| 945 | expect(menu._entry.active()).toEqual(false); |
| 946 | |
| 947 | // Forward |
| 948 | menu.next(); |
| 949 | expect(menu.prefix()).toEqual(""); |
| 950 | expect(menu.alwaysEntryValue()).toEqual(""); |
| 951 | expect(menu.shownItem(0).name()).toEqual("Veröffentlichungsdatum"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 952 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 953 | expect(menu.shownItem(0).active()).toBe(false); |
| 954 | expect(menu.shownItem(1).name()).toEqual("Länge"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 955 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Länge</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 956 | expect(menu.shownItem(1).active()).toBe(false); |
| 957 | expect(menu.shownItem(2).name()).toEqual("Autor"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 958 | expect(directElementChildrenByTagName(menu.element(),"li")[2].innerHTML).toEqual("<strong>Autor</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 959 | expect(menu.shownItem(2).active()).toBe(true); |
| 960 | expect(menu.shownItem(3)).toBe(undefined); |
| 961 | expect(menu._prefix.active()).toEqual(false); |
| 962 | expect(menu._entry.active()).toEqual(false); |
| 963 | |
| 964 | // Forward |
| 965 | menu.next(); |
| 966 | expect(menu.prefix()).toEqual(""); |
| 967 | expect(menu.alwaysEntryValue()).toEqual(""); |
| 968 | expect(menu.shownItem(0).name()).toEqual("Veröffentlichungsdatum"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 969 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 970 | expect(menu.shownItem(0).active()).toBe(false); |
| 971 | expect(menu.shownItem(1).name()).toEqual("Länge"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 972 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Länge</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 973 | expect(menu.shownItem(1).active()).toBe(false); |
| 974 | expect(menu.shownItem(2).name()).toEqual("Autor"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 975 | expect(directElementChildrenByTagName(menu.element(),"li")[2].innerHTML).toEqual("<strong>Autor</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 976 | expect(menu.shownItem(2).active()).toBe(false); |
| 977 | expect(menu.shownItem(3)).toBe(undefined); |
| 978 | expect(menu._prefix.active()).toEqual(false); |
| 979 | expect(menu._entry.active()).toEqual(true); |
| 980 | |
| 981 | // Forward |
| 982 | menu.next(); |
| 983 | expect(menu.prefix()).toEqual(""); |
| 984 | expect(menu.alwaysEntryValue()).toEqual(""); |
| 985 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 986 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Titel</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 987 | expect(menu.shownItem(0).active()).toBe(true); |
| 988 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 989 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Untertitel</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 990 | expect(menu.shownItem(1).active()).toBe(false); |
| 991 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 992 | expect(directElementChildrenByTagName(menu.element(),"li")[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 993 | expect(menu.shownItem(2).active()).toBe(false); |
| 994 | }); |
| 995 | |
| 996 | |
| 997 | it('should be navigatable with a prefix (1)', function () { |
| 998 | var menu = HintMenu.create("cnx/", demolist); |
| 999 | menu._firstActive = true; |
| 1000 | |
| 1001 | menu.limit(3); |
| 1002 | |
| 1003 | expect(menu.show()).toBe(true); |
| 1004 | expect(menu.prefix()).toEqual(""); |
| 1005 | expect(menu.alwaysEntryValue()).toEqual(""); |
| 1006 | |
| 1007 | // Add prefix in uppercase - but check in lowercase |
| 1008 | menu.prefix('El'); |
| 1009 | menu.alwaysEntryValue('El'); |
| 1010 | expect(menu.show()).toBe(true); |
| 1011 | |
| 1012 | expect(menu.prefix()).toEqual("El"); |
| 1013 | expect(menu._prefix.active()).toEqual(false); |
| 1014 | expect(menu.alwaysEntryValue()).toEqual("El"); |
| 1015 | expect(menu._entry.active()).toEqual(false); |
| 1016 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1017 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1018 | expect(menu.shownItem(0).active()).toBe(true); |
| 1019 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1020 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1021 | expect(menu.shownItem(1).active()).toBe(false); |
| 1022 | expect(menu.shownItem(2)).toBe(undefined); |
| 1023 | |
| 1024 | // Forward |
| 1025 | menu.next(); |
| 1026 | expect(menu.prefix()).toEqual("El"); |
| 1027 | expect(menu._prefix.active()).toEqual(false); |
| 1028 | expect(menu.alwaysEntryValue()).toEqual("El"); |
| 1029 | expect(menu._entry.active()).toEqual(false); |
| 1030 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1031 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1032 | expect(menu.shownItem(0).active()).toBe(false); |
| 1033 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1034 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1035 | expect(menu.shownItem(1).active()).toBe(true); |
| 1036 | expect(menu.shownItem(2)).toBe(undefined); |
| 1037 | |
| 1038 | // Forward |
| 1039 | menu.next(); |
| 1040 | expect(menu.prefix()).toEqual("El"); |
| 1041 | expect(menu._prefix.active()).toEqual(true); |
| 1042 | expect(menu.alwaysEntryValue()).toEqual("El"); |
| 1043 | expect(menu._entry.active()).toEqual(false); |
| 1044 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1045 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1046 | expect(menu.shownItem(0).active()).toBe(false); |
| 1047 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1048 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1049 | expect(menu.shownItem(1).active()).toBe(false); |
| 1050 | expect(menu.shownItem(2)).toBe(undefined); |
| 1051 | |
| 1052 | // Forward |
| 1053 | menu.next(); |
| 1054 | expect(menu.prefix()).toEqual("El"); |
| 1055 | expect(menu._prefix.active()).toEqual(false); |
| 1056 | expect(menu.alwaysEntryValue()).toEqual("El"); |
| 1057 | expect(menu._entry.active()).toEqual(true); |
| 1058 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1059 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1060 | expect(menu.shownItem(0).active()).toBe(false); |
| 1061 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1062 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1063 | expect(menu.shownItem(1).active()).toBe(false); |
| 1064 | expect(menu.shownItem(2)).toBe(undefined); |
| 1065 | |
| 1066 | menu.prev() |
| 1067 | expect(menu.prefix()).toEqual("El"); |
| 1068 | expect(menu._prefix.active()).toEqual(true); |
| 1069 | expect(menu.alwaysEntryValue()).toEqual("El"); |
| 1070 | expect(menu._entry.active()).toEqual(false); |
| 1071 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1072 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1073 | expect(menu.shownItem(0).active()).toBe(false); |
| 1074 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1075 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1076 | expect(menu.shownItem(1).active()).toBe(false); |
| 1077 | expect(menu.shownItem(2)).toBe(undefined); |
| 1078 | |
| 1079 | // Backward |
| 1080 | menu.prev(); |
| 1081 | expect(menu.prefix()).toEqual("El"); |
| 1082 | expect(menu._prefix.active()).toEqual(false); |
| 1083 | expect(menu.alwaysEntryValue()).toEqual("El"); |
| 1084 | expect(menu._entry.active()).toEqual(false); |
| 1085 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1086 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1087 | expect(menu.shownItem(0).active()).toBe(false); |
| 1088 | |
| 1089 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1090 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1091 | expect(menu.shownItem(1).active()).toBe(true); |
| 1092 | expect(menu.shownItem(2)).toBe(undefined); |
| 1093 | }); |
| 1094 | |
| 1095 | |
| 1096 | it('should be navigatable with a prefix (2)', function () { |
| 1097 | var menu = HintMenu.create("cnx/", demolist); |
| 1098 | menu._firstActive = true; |
| 1099 | |
| 1100 | menu.limit(3); |
| 1101 | expect(menu.show()).toBe(true); |
| 1102 | expect(menu.prefix()).toEqual(""); |
| 1103 | menu.prefix('el'); |
| 1104 | expect(menu.alwaysEntryValue()).toEqual(""); |
| 1105 | menu.alwaysEntryValue('el'); |
| 1106 | expect(menu.show()).toBe(true); |
| 1107 | |
| 1108 | expect(menu.prefix()).toEqual("el"); |
| 1109 | expect(menu._prefix.active()).toEqual(false); |
| 1110 | expect(menu.alwaysEntryValue()).toEqual("el"); |
| 1111 | expect(menu._entry.active()).toEqual(false); |
| 1112 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1113 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1114 | expect(menu.shownItem(0).active()).toBe(true); |
| 1115 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1116 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1117 | expect(menu.shownItem(1).active()).toBe(false); |
| 1118 | expect(menu.shownItem(2)).toBe(undefined); |
| 1119 | |
| 1120 | // Backward |
| 1121 | menu.prev(); |
| 1122 | expect(menu._prefix.active()).toEqual(false); |
| 1123 | expect(menu._entry.active()).toEqual(true); |
| 1124 | |
| 1125 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1126 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1127 | expect(menu.shownItem(0).active()).toBe(false); |
| 1128 | |
| 1129 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1130 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1131 | expect(menu.shownItem(1).active()).toBe(false); |
| 1132 | expect(menu.shownItem(2)).toBe(undefined); |
| 1133 | |
| 1134 | |
| 1135 | // Backward |
| 1136 | menu.prev(); |
| 1137 | expect(menu._prefix.active()).toEqual(true); |
| 1138 | expect(menu._entry.active()).toEqual(false); |
| 1139 | |
| 1140 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1141 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1142 | expect(menu.shownItem(0).active()).toBe(false); |
| 1143 | |
| 1144 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1145 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1146 | expect(menu.shownItem(1).active()).toBe(false); |
| 1147 | expect(menu.shownItem(2)).toBe(undefined); |
| 1148 | |
| 1149 | // Backward |
| 1150 | menu.prev(); |
| 1151 | expect(menu._prefix.active()).toEqual(false); |
| 1152 | expect(menu._entry.active()).toEqual(false); |
| 1153 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1154 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1155 | expect(menu.shownItem(0).active()).toBe(false); |
| 1156 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1157 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1158 | expect(menu.shownItem(1).active()).toBe(true); |
| 1159 | expect(menu.shownItem(2)).toBe(undefined); |
| 1160 | }); |
| 1161 | |
| 1162 | it('should be navigatable with a prefix (3)', function () { |
| 1163 | var menu = HintMenu.create("cnx/", demolist); |
| 1164 | menu._firstActive = true; |
| 1165 | menu.limit(3); |
| 1166 | expect(menu.show()).toBe(true); |
| 1167 | expect(menu.prefix()).toEqual(""); |
| 1168 | menu.prefix('el'); |
| 1169 | expect(menu.alwaysEntryValue()).toEqual(""); |
| 1170 | expect(menu.alwaysEntry().value()).toEqual(""); |
| 1171 | menu.alwaysEntryValue('el'); |
| 1172 | expect(menu.show()).toBe(true); |
| 1173 | |
| 1174 | expect(menu.prefix()).toEqual("el"); |
| 1175 | expect(menu._prefix.active()).toEqual(false); |
| 1176 | expect(menu.alwaysEntry().value()).toEqual("el"); |
| 1177 | expect(menu._entry.active()).toEqual(false); |
| 1178 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1179 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1180 | expect(menu.shownItem(0).active()).toBe(true); |
| 1181 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1182 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1183 | expect(menu.shownItem(1).active()).toBe(false); |
| 1184 | expect(menu.shownItem(2)).toBe(undefined); |
| 1185 | |
| 1186 | // Backward |
| 1187 | menu.prev(); |
| 1188 | expect(menu._prefix.active()).toEqual(false); |
| 1189 | expect(menu._entry.active()).toEqual(true); |
| 1190 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1191 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1192 | expect(menu.shownItem(0).active()).toBe(false); |
| 1193 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1194 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1195 | expect(menu.shownItem(1).active()).toBe(false); |
| 1196 | expect(menu.shownItem(2)).toBe(undefined); |
| 1197 | |
| 1198 | // Backward |
| 1199 | menu.prev(); |
| 1200 | expect(menu._prefix.active()).toEqual(true); |
| 1201 | expect(menu._entry.active()).toEqual(false); |
| 1202 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1203 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1204 | expect(menu.shownItem(0).active()).toBe(false); |
| 1205 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1206 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1207 | expect(menu.shownItem(1).active()).toBe(false); |
| 1208 | expect(menu.shownItem(2)).toBe(undefined); |
| 1209 | |
| 1210 | |
| 1211 | // Forward |
| 1212 | menu.next(); |
| 1213 | expect(menu.prefix()).toEqual("el"); |
| 1214 | expect(menu._prefix.active()).toEqual(false); |
| 1215 | expect(menu._entry.active()).toEqual(true); |
| 1216 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1217 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1218 | expect(menu.shownItem(0).active()).toBe(false); |
| 1219 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1220 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1221 | expect(menu.shownItem(1).active()).toBe(false); |
| 1222 | expect(menu.shownItem(2)).toBe(undefined); |
| 1223 | |
| 1224 | // Forward |
| 1225 | menu.next(); |
| 1226 | expect(menu.prefix()).toEqual("el"); |
| 1227 | expect(menu._prefix.active()).toEqual(false); |
| 1228 | expect(menu._entry.active()).toEqual(false); |
| 1229 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1230 | expect(directElementChildrenByTagName(menu.element(),"li")[0].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1231 | expect(menu.shownItem(0).active()).toBe(true); |
| 1232 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
Leo Repp | dedcf1a | 2021-08-18 18:57:47 +0200 | [diff] [blame] | 1233 | expect(directElementChildrenByTagName(menu.element(),"li")[1].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1234 | expect(menu.shownItem(1).active()).toBe(false); |
| 1235 | expect(menu.shownItem(2)).toBe(undefined); |
| 1236 | }); |
| 1237 | |
| 1238 | |
| 1239 | |
| 1240 | xit('should scroll to a chosen value after prefixing, if the chosen value is live'); |
| 1241 | }); |
| 1242 | |
| 1243 | describe('KorAP.AlwaysMenu.Entry', function () { |
| 1244 | it('should be initializable', function () { |
| 1245 | var p = alwaysEntryClass.create(); |
marcrusian | 235a23a | 2021-05-26 14:28:11 +0200 | [diff] [blame] | 1246 | expect(p.element().classList.contains('pref')).toBeFalsy(); |
| 1247 | expect(p.element().classList.contains('entry')).toBeTruthy(); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1248 | expect(p.isSet()).not.toBeTruthy(); |
| 1249 | expect(p.element().innerHTML).toEqual("Speichern"); |
| 1250 | expect(p.value()).toEqual(""); |
| 1251 | |
| 1252 | /* |
| 1253 | expect(mi.lcField()).toEqual(' baum'); |
| 1254 | */ |
| 1255 | |
| 1256 | }); |
| 1257 | |
| 1258 | it('should be initializable with a different name', function () { |
| 1259 | var p = alwaysEntryClass.create("Save"); |
marcrusian | 235a23a | 2021-05-26 14:28:11 +0200 | [diff] [blame] | 1260 | expect(p.element().classList.contains('pref')).toBeFalsy(); |
| 1261 | expect(p.element().classList.contains('entry')).toBeTruthy(); |
Leo Repp | 56904d2 | 2021-04-26 15:53:22 +0200 | [diff] [blame] | 1262 | expect(p.isSet()).not.toBeTruthy(); |
| 1263 | expect(p.element().innerHTML).toEqual("Save"); |
| 1264 | expect(p.value()).toEqual(""); |
| 1265 | |
| 1266 | /* |
| 1267 | expect(mi.lcField()).toEqual(' baum'); |
| 1268 | */ |
| 1269 | |
| 1270 | }); |
| 1271 | |
| 1272 | it('should be modifiable', function () { |
| 1273 | var p = alwaysEntryClass.create(); |
| 1274 | expect(p.value()).toEqual(''); |
| 1275 | expect(p.element().firstChild).toEqual(document.createTextNode("Speichern")); |
| 1276 | |
| 1277 | // Set string |
| 1278 | expect(p.value('Test')).toEqual('Test'); |
| 1279 | expect(p.value()).toEqual('Test'); |
| 1280 | expect(p.element().firstChild.nodeValue).toEqual('Speichern'); |
| 1281 | |
| 1282 | // Add string |
| 1283 | expect(p.add('ified')).toEqual('Testified'); |
| 1284 | expect(p.value()).toEqual('Testified'); |
| 1285 | expect(p.element().firstChild.nodeValue).toEqual('Speichern'); |
| 1286 | |
| 1287 | // Clear string |
| 1288 | p.clear(); |
| 1289 | expect(p.value()).toEqual(''); |
| 1290 | expect(p.element().firstChild).toEqual(document.createTextNode("Speichern")); |
| 1291 | |
| 1292 | // Set string |
| 1293 | expect(p.value('Test')).toEqual('Test'); |
| 1294 | expect(p.value()).toEqual('Test'); |
| 1295 | expect(p.element().firstChild.nodeValue).toEqual('Speichern'); |
| 1296 | |
| 1297 | expect(p.chop()).toEqual('Tes'); |
| 1298 | expect(p.value()).toEqual('Tes'); |
| 1299 | expect(p.element().firstChild.nodeValue).toEqual('Speichern'); |
| 1300 | |
| 1301 | expect(p.chop()).toEqual('Te'); |
| 1302 | expect(p.value()).toEqual('Te'); |
| 1303 | expect(p.element().firstChild.nodeValue).toEqual('Speichern'); |
| 1304 | |
| 1305 | expect(p.chop()).toEqual('T'); |
| 1306 | expect(p.value()).toEqual('T'); |
| 1307 | expect(p.element().firstChild.nodeValue).toEqual('Speichern'); |
| 1308 | |
| 1309 | expect(p.chop()).toEqual(''); |
| 1310 | expect(p.value()).toEqual(''); |
| 1311 | expect(p.element().firstChild).toEqual(document.createTextNode("Speichern")); |
| 1312 | }); |
| 1313 | |
| 1314 | it('should be activatable', function () { |
| 1315 | var p = alwaysEntryClass.create(); |
| 1316 | expect(p.value()).toEqual(''); |
| 1317 | expect(p.element().firstChild).toEqual(document.createTextNode("Speichern")); |
| 1318 | |
| 1319 | expect(p.value('Test')).toEqual('Test'); |
| 1320 | expect(p.element().firstChild.nodeValue).toEqual('Speichern'); |
| 1321 | |
| 1322 | expect(p.active()).not.toBeTruthy(); |
| 1323 | expect(p.element().classList.contains('active')).not.toBeTruthy(); |
| 1324 | |
| 1325 | p.active(true); |
| 1326 | expect(p.active()).toBeTruthy(); |
| 1327 | expect(p.element().classList.contains('active')).toBeTruthy(); |
| 1328 | }); |
| 1329 | }); |
| 1330 | |
| 1331 | describe('KorAP.AlwaysMenu.Slider', function () { |
| 1332 | |
| 1333 | var demolonglist = [ |
| 1334 | ['Titel', 'title'], |
| 1335 | ['Untertitel', 'subTitle'], |
| 1336 | ['Veröffentlichungsdatum', 'pubDate'], |
| 1337 | ['Länge', 'length'], |
| 1338 | ['Autor', 'author'], |
| 1339 | ['Genre', 'genre'], |
| 1340 | ['corpusID', 'corpusID'], |
| 1341 | ['docID', 'docID'], |
| 1342 | ['textID', 'textID'], |
| 1343 | ]; |
| 1344 | |
| 1345 | it('should correctly be initializable', function () { |
| 1346 | var list = [ |
| 1347 | ["Constituency"], |
| 1348 | ["Lemma"], |
| 1349 | ["Morphology"], |
| 1350 | ["Part-of-Speech"], |
| 1351 | ["Syntax"] |
| 1352 | ]; |
| 1353 | |
| 1354 | var menu = OwnAlwaysMenu.create(list); |
| 1355 | |
| 1356 | menu._firstActive = true; |
| 1357 | menu.limit(3); |
| 1358 | |
| 1359 | expect(menu.show()).toBe(true); |
| 1360 | |
| 1361 | expect(menu.shownItem(0).active()).toBe(true); |
| 1362 | expect(menu.shownItem(1).active()).toBe(false); |
| 1363 | expect(menu.shownItem(2).active()).toBe(false); |
| 1364 | expect(menu.slider().offset()).toEqual(0); |
| 1365 | expect(menu.position).toEqual(0); |
| 1366 | }); |
| 1367 | |
| 1368 | it('should correctly move on arrow keys', function () { |
| 1369 | var list = [ |
| 1370 | ["Constituency"], |
| 1371 | ["Lemma"], |
| 1372 | ["Morphology"], |
| 1373 | ["Part-of-Speech"], |
| 1374 | ["Syntax"] |
| 1375 | ]; |
| 1376 | |
| 1377 | var menu = OwnAlwaysMenu.create(list); |
| 1378 | |
| 1379 | menu._firstActive = true; |
| 1380 | menu.limit(3); |
| 1381 | |
| 1382 | expect(menu.show()).toBe(true); |
| 1383 | |
| 1384 | menu.next(); |
| 1385 | expect(menu.shownItem(0).active()).toBe(false); |
| 1386 | expect(menu.shownItem(1).active()).toBe(true); |
| 1387 | expect(menu.shownItem(2).active()).toBe(false); |
| 1388 | expect(menu._prefix.active()).toBe(false); |
| 1389 | expect(menu._entry.active()).toBe(false); |
| 1390 | expect(menu.slider().offset()).toEqual(0); |
| 1391 | expect(menu.position).toEqual(1); |
| 1392 | |
| 1393 | menu.next(); |
| 1394 | expect(menu.shownItem(0).active()).toBe(false); |
| 1395 | expect(menu.shownItem(1).active()).toBe(false); |
| 1396 | expect(menu.shownItem(2).active()).toBe(true); |
| 1397 | expect(menu._prefix.active()).toBe(false); |
| 1398 | expect(menu._entry.active()).toBe(false); |
| 1399 | expect(menu.slider().offset()).toEqual(0); |
| 1400 | expect(menu.position).toEqual(2); |
| 1401 | |
| 1402 | menu.next(); |
| 1403 | expect(menu.shownItem(0).active()).toBe(false); |
| 1404 | expect(menu.shownItem(1).active()).toBe(false); |
| 1405 | expect(menu.shownItem(2).active()).toBe(true); |
| 1406 | expect(menu._prefix.active()).toBe(false); |
| 1407 | expect(menu._entry.active()).toBe(false); |
| 1408 | expect(menu.slider().offset()).toEqual(1); |
| 1409 | expect(menu.position).toEqual(3); |
| 1410 | |
| 1411 | menu.next(); |
| 1412 | expect(menu.shownItem(0).active()).toBe(false); |
| 1413 | expect(menu.shownItem(1).active()).toBe(false); |
| 1414 | expect(menu.shownItem(2).active()).toBe(true); |
| 1415 | expect(menu._prefix.active()).toBe(false); |
| 1416 | expect(menu._entry.active()).toBe(false); |
| 1417 | expect(menu.slider().offset()).toEqual(2); |
| 1418 | expect(menu.position).toEqual(4); |
| 1419 | |
| 1420 | menu.next(); |
| 1421 | expect(menu.shownItem(0).active()).toBe(false); |
| 1422 | expect(menu.shownItem(1).active()).toBe(false); |
| 1423 | expect(menu.shownItem(2).active()).toBe(false); |
| 1424 | expect(menu._prefix.active()).toBe(false); |
| 1425 | expect(menu._entry.active()).toBe(true); |
| 1426 | expect(menu.slider().offset()).toEqual(2); |
| 1427 | expect(menu.position).toEqual(7); |
| 1428 | |
| 1429 | menu.next(); |
| 1430 | expect(menu.shownItem(0).active()).toBe(true); |
| 1431 | expect(menu.shownItem(1).active()).toBe(false); |
| 1432 | expect(menu.shownItem(2).active()).toBe(false); |
| 1433 | expect(menu._prefix.active()).toBe(false); |
| 1434 | expect(menu._entry.active()).toBe(false); |
| 1435 | expect(menu.slider().offset()).toEqual(0); |
| 1436 | expect(menu.position).toEqual(0); |
| 1437 | |
| 1438 | expect(menu.slider()._slider.style.height).toEqual('60%'); |
| 1439 | }); |
| 1440 | |
| 1441 | }); |
| 1442 | |
| 1443 | describe('KorAP.AlwaysMenu.Benchmark', function () { |
| 1444 | var menu = alwaysMenuClass.create([ |
| 1445 | ['Titel', 'title'], |
| 1446 | ['Untertitel', 'subTitle'], |
| 1447 | ['Veröffentlichungsdatum', 'pubDate'], |
| 1448 | ['Länge', 'length'], |
| 1449 | ['Autor', 'author'] |
| 1450 | ]); |
| 1451 | |
| 1452 | menu.limit(3).show(); |
| 1453 | |
| 1454 | // Some actions |
| 1455 | menu.next(); |
| 1456 | menu.next(); |
| 1457 | menu.prev(); |
| 1458 | menu.prev(); |
| 1459 | menu.prev(); |
| 1460 | |
| 1461 | menu.pageDown(); |
| 1462 | menu.pageUp(); |
| 1463 | |
| 1464 | // There is no fourth item in the list! |
| 1465 | menu.prefix('e').show(4); |
| 1466 | menu.next(); |
| 1467 | menu.next(); |
| 1468 | menu.prev(); |
| 1469 | menu.prev(); |
| 1470 | menu.prev(); |
| 1471 | }); |
| 1472 | }); |