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