Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 1 | // The OwnMenu item |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 2 | KorAP.OwnMenuItem = { |
| 3 | create : function (params) { |
| 4 | return Object.create(KorAP.MenuItem).upgradeTo(KorAP.OwnMenuItem)._init(params); |
| 5 | }, |
| 6 | content : function (content) { |
| 7 | if (arguments.length === 1) { |
| 8 | this._content = content; |
| 9 | }; |
| 10 | return this._content; |
| 11 | }, |
| 12 | _init : function (params) { |
| 13 | if (params[0] === undefined) |
| 14 | throw new Error("Missing parameters"); |
| 15 | |
| 16 | this._content = document.createTextNode(params[0]); |
| 17 | this._lcField = ' ' + this.content().textContent.toLowerCase(); |
| 18 | |
| 19 | return this; |
| 20 | } |
| 21 | }; |
| 22 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 23 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 24 | // The OwnMenu |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 25 | KorAP.OwnMenu = { |
| 26 | create : function (params) { |
| 27 | return Object.create(KorAP.Menu) |
| 28 | .upgradeTo(KorAP.OwnMenu) |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 29 | ._init(KorAP.OwnMenuItem, undefined, params); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 30 | } |
| 31 | }; |
| 32 | |
| 33 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 34 | // HintMenuItem |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 35 | KorAP.HintMenuItem = { |
| 36 | create : function (params) { |
| 37 | return Object.create(KorAP.MenuItem) |
| 38 | .upgradeTo(KorAP.HintMenuItem) |
| 39 | ._init(params); |
| 40 | }, |
| 41 | content : function (content) { |
| 42 | if (arguments.length === 1) { |
| 43 | this._content = content; |
| 44 | }; |
| 45 | return this._content; |
| 46 | }, |
| 47 | _init : function (params) { |
| 48 | if (params[0] === undefined || params[1] === undefined) |
| 49 | throw new Error("Missing parameters"); |
| 50 | |
| 51 | this._name = params[0]; |
| 52 | this._action = params[1]; |
| 53 | this._lcField = ' ' + this._name.toLowerCase(); |
| 54 | |
| 55 | if (params.length > 2) { |
| 56 | this._desc = params[2]; |
| 57 | this._lcField += " " + this._desc.toLowerCase(); |
| 58 | }; |
| 59 | |
| 60 | return this; |
| 61 | }, |
| 62 | name : function () { |
| 63 | return this._name; |
| 64 | }, |
| 65 | action : function () { |
| 66 | return this._action; |
| 67 | }, |
| 68 | desc : function () { |
| 69 | return this._desc; |
| 70 | }, |
| 71 | element : function () { |
| 72 | // already defined |
| 73 | if (this._element !== undefined) |
| 74 | return this._element; |
| 75 | |
| 76 | // Create list item |
| 77 | var li = document.createElement("li"); |
| 78 | li.setAttribute("data-action", this._action); |
| 79 | |
| 80 | // Create title |
| 81 | var name = document.createElement("strong"); |
| 82 | name.appendChild(document.createTextNode(this._name)); |
| 83 | |
| 84 | li.appendChild(name); |
| 85 | |
| 86 | // Create description |
| 87 | if (this._desc !== undefined) { |
| 88 | var desc = document.createElement("span"); |
| 89 | desc.appendChild(document.createTextNode(this._desc)); |
| 90 | li.appendChild(desc); |
| 91 | }; |
| 92 | return this._element = li; |
| 93 | } |
| 94 | }; |
| 95 | |
| 96 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 97 | // HintMenu |
| 98 | KorAP.HintMenu = { |
| 99 | create : function (context, params) { |
| 100 | var obj = Object.create(KorAP.Menu) |
| 101 | .upgradeTo(KorAP.HintMenu) |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 102 | ._init(KorAP.HintMenuItem, undefined, params); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 103 | obj._context = context; |
| 104 | return obj; |
| 105 | } |
| 106 | }; |
| 107 | |
| 108 | |
| 109 | // The ComplexMenuItem |
| 110 | KorAP.ComplexMenuItem = { |
| 111 | create : function (params) { |
| 112 | return Object.create(KorAP.MenuItem) |
| 113 | .upgradeTo(KorAP.ComplexMenuItem) |
| 114 | ._init(params); |
| 115 | }, |
| 116 | content : function (content) { |
| 117 | if (arguments.length === 1) { |
| 118 | this._content = content; |
| 119 | }; |
| 120 | return this._content; |
| 121 | }, |
| 122 | _init : function (params) { |
| 123 | if (params[0] === undefined) |
| 124 | throw new Error("Missing parameters"); |
| 125 | |
| 126 | var r = document.createElement('div'); |
| 127 | for (var i = 1; i <= params.length; i++) { |
| 128 | var h = document.createElement('h' + i); |
| 129 | h.appendChild(document.createTextNode(params[i-1])); |
| 130 | r.appendChild(h); |
| 131 | }; |
| 132 | |
| 133 | this._content = r; |
| 134 | this._lcField = ' ' + this.content().textContent.toLowerCase(); |
| 135 | |
| 136 | return this; |
| 137 | } |
| 138 | }; |
| 139 | |
| 140 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 141 | |
| 142 | describe('KorAP.MenuItem', function () { |
| 143 | it('should be initializable', function () { |
| 144 | expect( |
| 145 | function() { KorAP.MenuItem.create([]) } |
| 146 | ).toThrow(new Error("Missing parameters")); |
| 147 | |
| 148 | expect( |
| 149 | function() { KorAP.OwnMenuItem.create([]) } |
| 150 | ).toThrow(new Error("Missing parameters")); |
| 151 | |
| 152 | var mi = KorAP.OwnMenuItem.create(["Baum"]); |
| 153 | expect(mi.element().firstChild.nodeValue).toEqual('Baum'); |
| 154 | expect(mi.lcField()).toEqual(' baum'); |
| 155 | }); |
| 156 | |
Nils Diewald | 6e43ffd | 2015-03-25 18:55:39 +0000 | [diff] [blame^] | 157 | it('shouldn\'t have a reference to the menu', function () { |
| 158 | var menuItem = KorAP.OwnMenuItem.create(['Test']); |
| 159 | expect(menuItem.menu()).toBe(undefined); |
| 160 | }); |
| 161 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 162 | it('should be activatable and deactivateable by class', function () { |
| 163 | var menuItem = KorAP.OwnMenuItem.create(['Test']); |
| 164 | |
| 165 | expect(menuItem.active()).toBe(false); |
| 166 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 167 | menuItem.active(true); |
| 168 | expect(menuItem.active()).toBe(true); |
| 169 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
| 170 | menuItem.active(false); // Is active |
| 171 | expect(menuItem.active()).toBe(false); |
| 172 | expect(menuItem.element().getAttribute("class")).toEqual(""); |
| 173 | menuItem.active(true); |
| 174 | expect(menuItem.active()).toBe(true); |
| 175 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
| 176 | |
| 177 | menuItem = KorAP.OwnMenuItem.create(['Spiegel']); |
| 178 | expect(menuItem.active()).toBe(false); |
| 179 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 180 | menuItem.active(false); // Is not active |
| 181 | expect(menuItem.active()).toBe(false); |
| 182 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 183 | }); |
| 184 | |
| 185 | it('should be set to boundary', function () { |
| 186 | var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']); |
| 187 | expect(menuItem.active()).toBe(false); |
| 188 | expect(menuItem.element().getAttribute("class")).toBe(null); |
| 189 | |
| 190 | // Set active |
| 191 | menuItem.active(true); |
| 192 | expect(menuItem.active()).toBe(true); |
| 193 | expect(menuItem.noMore()).toBe(false); |
| 194 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
| 195 | |
| 196 | // Set no more |
| 197 | menuItem.noMore(true); |
| 198 | expect(menuItem.active()).toBe(true); |
| 199 | expect(menuItem.noMore()).toBe(true); |
| 200 | expect(menuItem.element().getAttribute("class")).toEqual("active no-more"); |
| 201 | |
| 202 | // No no more |
| 203 | menuItem.noMore(false); |
| 204 | expect(menuItem.active()).toBe(true); |
| 205 | expect(menuItem.noMore()).toBe(false); |
| 206 | expect(menuItem.element().getAttribute("class")).toEqual("active"); |
| 207 | |
| 208 | // Set no more, deactivate |
| 209 | menuItem.noMore(true); |
| 210 | menuItem.active(false); |
| 211 | expect(menuItem.active()).toBe(false); |
| 212 | expect(menuItem.noMore()).toBe(true); |
| 213 | expect(menuItem.element().getAttribute("class")).toEqual("no-more"); |
| 214 | |
| 215 | // Set active |
| 216 | menuItem.active(true); |
| 217 | expect(menuItem.active()).toBe(true); |
| 218 | expect(menuItem.noMore()).toBe(true); |
| 219 | expect(menuItem.element().getAttribute("class")).toEqual("no-more active"); |
| 220 | }); |
| 221 | |
| 222 | |
| 223 | it('should be highlightable', function () { |
| 224 | // Highlight in the middle |
| 225 | var menuItem = KorAP.OwnMenuItem.create(['CoreNLP']); |
| 226 | menuItem.highlight("ren"); |
| 227 | expect(menuItem.element().innerHTML).toEqual("Co<mark>reN</mark>LP"); |
| 228 | |
| 229 | menuItem.lowlight(); |
| 230 | expect(menuItem.element().innerHTML).toEqual("CoreNLP"); |
| 231 | |
| 232 | var plain = "<div><h1>CoreNLP</h1><h2>corenlp/</h2></div>"; |
| 233 | |
| 234 | // Starting highlight |
| 235 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']); |
| 236 | menuItem.highlight("cor"); |
| 237 | expect(menuItem.element().innerHTML).toEqual("<div><h1><mark>Cor</mark>eNLP</h1><h2><mark>cor</mark>enlp/</h2></div>"); |
| 238 | |
| 239 | menuItem.lowlight(); |
| 240 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 241 | |
| 242 | // Starting highlight - short |
| 243 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']); |
| 244 | menuItem.highlight("c"); |
| 245 | expect(menuItem.element().innerHTML).toEqual("<div><h1><mark>C</mark>oreNLP</h1><h2><mark>c</mark>orenlp/</h2></div>"); |
| 246 | |
| 247 | menuItem.lowlight(); |
| 248 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 249 | |
| 250 | // Highlight at the end |
| 251 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']); |
| 252 | menuItem.highlight("nlp"); |
| 253 | expect(menuItem.element().innerHTML).toEqual("<div><h1>Core<mark>NLP</mark></h1><h2>core<mark>nlp</mark>/</h2></div>"); |
| 254 | |
| 255 | menuItem.lowlight(); |
| 256 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 257 | |
| 258 | // Highlight at the end - short |
| 259 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']); |
| 260 | menuItem.highlight("p"); |
| 261 | expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNL<mark>P</mark></h1><h2>corenl<mark>p</mark>/</h2></div>"); |
| 262 | |
| 263 | menuItem.lowlight(); |
| 264 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 265 | |
| 266 | // No highlight |
| 267 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/']); |
| 268 | menuItem.highlight("xp"); |
| 269 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 270 | |
| 271 | menuItem.lowlight(); |
| 272 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 273 | |
| 274 | // Highlight in the middle - first |
| 275 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 276 | menuItem.highlight("ren"); |
| 277 | 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>"); |
| 278 | |
| 279 | plain = "<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Example</h3></div>" |
| 280 | |
| 281 | menuItem.lowlight(); |
| 282 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 283 | |
| 284 | // Highlight in the middle - second |
| 285 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 286 | menuItem.highlight("ampl"); |
| 287 | expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Ex<mark>ampl</mark>e</h3></div>"); |
| 288 | |
| 289 | menuItem.lowlight(); |
| 290 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 291 | |
| 292 | // Highlight in the middle - both |
| 293 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 294 | menuItem.highlight("e"); |
| 295 | 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>"); |
| 296 | |
| 297 | menuItem.lowlight(); |
| 298 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 299 | |
| 300 | // Highlight in the end - second |
| 301 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 302 | menuItem.highlight("le"); |
| 303 | expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3>This is my Examp<mark>le</mark></h3></div>"); |
| 304 | |
| 305 | menuItem.lowlight(); |
| 306 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 307 | |
| 308 | // Highlight at the beginning - second |
| 309 | menuItem = KorAP.ComplexMenuItem.create(['CoreNLP', 'corenlp/', 'This is my Example']); |
| 310 | menuItem.highlight("this"); |
| 311 | expect(menuItem.element().innerHTML).toEqual("<div><h1>CoreNLP</h1><h2>corenlp/</h2><h3><mark>This</mark> is my Example</h3></div>"); |
| 312 | |
| 313 | menuItem.lowlight(); |
| 314 | expect(menuItem.element().innerHTML).toEqual(plain); |
| 315 | }); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 316 | }); |
| 317 | |
| 318 | |
| 319 | describe('KorAP.Menu', function () { |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 320 | var list = [ |
| 321 | ["Constituency", "c=", "Example 1"], |
| 322 | ["Lemma", "l="], |
| 323 | ["Morphology", "m=", "Example 2"], |
| 324 | ["Part-of-Speech", "p="], |
| 325 | ["Syntax", "syn="] |
| 326 | ]; |
| 327 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 328 | var demolist = [ |
| 329 | ['Titel', 'title'], |
| 330 | ['Untertitel', 'subTitle'], |
| 331 | ['Veröffentlichungsdatum', 'pubDate'], |
| 332 | ['Länge', 'length'], |
| 333 | ['Autor', 'author'] |
| 334 | ]; |
| 335 | |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 336 | var demolonglist = [ |
| 337 | ['Titel', 'title'], |
| 338 | ['Untertitel', 'subTitle'], |
| 339 | ['Veröffentlichungsdatum', 'pubDate'], |
| 340 | ['Länge', 'length'], |
| 341 | ['Autor', 'author'], |
| 342 | ['Genre', 'genre'], |
| 343 | ['corpusID', 'corpusID'], |
| 344 | ['docID', 'docID'], |
| 345 | ['textID', 'textID'], |
| 346 | ]; |
| 347 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 348 | it('should be initializable', function () { |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 349 | var list = [ |
| 350 | ["Constituency"], |
| 351 | ["Lemma"], |
| 352 | ["Morphology"], |
| 353 | ["Part-of-Speech"], |
| 354 | ["Syntax"] |
| 355 | ]; |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 356 | |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 357 | var menu = KorAP.OwnMenu.create(list); |
| 358 | expect(menu.itemClass()).toEqual(KorAP.OwnMenuItem); |
| 359 | expect(menu.element().nodeName).toEqual('UL'); |
| 360 | expect(menu.element().style.opacity).toEqual("0"); |
| 361 | expect(menu.limit()).toEqual(8); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 362 | |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 363 | menu.limit(9); |
| 364 | expect(menu.limit()).toEqual(9); |
| 365 | |
| 366 | menu.limit(8); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 367 | |
| 368 | // view |
| 369 | menu.show(); |
| 370 | |
| 371 | // First element in list |
| 372 | expect(menu.item(0).active()).toBe(true); |
| 373 | expect(menu.item(0).noMore()).toBe(true); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 374 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 375 | // Middle element in list |
| 376 | expect(menu.item(2).active()).toBe(false); |
| 377 | expect(menu.item(2).noMore()).toBe(false); |
| 378 | |
| 379 | // Last element in list |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 380 | expect(menu.item(menu.length() - 1).active()).toBe(false); |
| 381 | expect(menu.item(menu.length() - 1).noMore()).toBe(true); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 382 | }); |
| 383 | |
Nils Diewald | 6e43ffd | 2015-03-25 18:55:39 +0000 | [diff] [blame^] | 384 | it('should have a reference to the menu', function () { |
| 385 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 386 | expect(menu.item(0).menu()).toEqual(menu); |
| 387 | |
| 388 | menu = KorAP.HintMenu.create("cnx/", list); |
| 389 | expect(menu.element().menu).toEqual(menu); |
| 390 | }); |
| 391 | |
| 392 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 393 | it('should be visible', function () { |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 394 | var menu = KorAP.HintMenu.create("cnx/", list); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 395 | expect(menu.delete()).toBe(undefined); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 396 | menu.limit(3); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 397 | |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 398 | expect(menu.show()).toBe(true); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 399 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 400 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
| 401 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>"); |
| 402 | expect(menu.element().childNodes[2].getAttribute("data-action")).toEqual("l="); |
| 403 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 404 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 405 | |
| 406 | // Check boundaries |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 407 | expect(menu.element().childNodes[1].classList.contains("no-more")).toBe(true); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 408 | expect(menu.element().childNodes[2].classList.contains("no-more")).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 409 | expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(false); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 410 | }); |
| 411 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 412 | it('should be filterable', function () { |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 413 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 414 | menu.limit(3); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 415 | expect(menu.prefix("o").show()).toBe(true); |
| 416 | expect(menu.element().childNodes[0].innerHTML).toEqual("o"); |
| 417 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
| 418 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>"); |
| 419 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>"); |
| 420 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 421 | |
| 422 | // Check boundaries |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 423 | expect(menu.element().childNodes[1].classList.contains("no-more")).toBe(true); |
| 424 | expect(menu.element().childNodes[2].classList.contains("no-more")).toBe(false); |
| 425 | expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(true); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 426 | |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 427 | menu.limit(2); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 428 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 429 | expect(menu.prefix("o").show()).toBe(true); |
| 430 | expect(menu.element().childNodes[0].innerHTML).toEqual("o"); |
| 431 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
| 432 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>"); |
| 433 | expect(menu.element().childNodes[3]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 434 | |
| 435 | // Check boundaries |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 436 | expect(menu.element().childNodes[1].classList.contains("no-more")).toBe(true); |
| 437 | expect(menu.element().childNodes[2].classList.contains("no-more")).toBe(false); |
| 438 | expect(menu.element().childNodes[3]).toBe(undefined); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 439 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 440 | expect(menu.prefix("e").show()).toBe(true); |
| 441 | expect(menu.element().childNodes[0].innerHTML).toEqual("e"); |
| 442 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
| 443 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
| 444 | expect(menu.element().childNodes[3]).toBe(undefined); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 445 | |
| 446 | menu.limit(5); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 447 | expect(menu.prefix("a").show()).toBe(true); |
| 448 | expect(menu.element().childNodes[0].innerHTML).toEqual("a"); |
| 449 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Ex<mark>a</mark>mple 1</span>"); |
| 450 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemm<mark>a</mark></strong>"); |
| 451 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Ex<mark>a</mark>mple 2</span>"); |
| 452 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>P<mark>a</mark>rt-of-Speech</strong>"); |
| 453 | expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Synt<mark>a</mark>x</strong>"); |
| 454 | expect(menu.element().childNodes[6]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 455 | }); |
| 456 | |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 457 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 458 | it('should be nextable', function () { |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 459 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 460 | |
| 461 | // Show only 3 items |
| 462 | menu.limit(3); |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 463 | expect(menu.show()).toBe(true); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 464 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 465 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 466 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 467 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 468 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 469 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 470 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 471 | |
| 472 | // Activate next (1) |
| 473 | menu.next(); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 474 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 475 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 476 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 477 | expect(menu.shownItem(1).active()).toBe(true); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 478 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 479 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 480 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 481 | |
| 482 | // Activate next (2) |
| 483 | menu.next(); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 484 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 485 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 486 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 487 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 488 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 489 | expect(menu.shownItem(2).active()).toBe(true); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 490 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 491 | |
| 492 | // Activate next (3) |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 493 | // scroll! |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 494 | menu.next(); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 495 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 496 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 497 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 498 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 499 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 500 | expect(menu.shownItem(2).active()).toBe(true); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 501 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 502 | |
| 503 | // Activate next (4) |
| 504 | menu.next(); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 505 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 506 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 507 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 508 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 509 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Syntax</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 510 | expect(menu.shownItem(2).active()).toBe(true); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 511 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 512 | |
| 513 | // Activate next (5) - ROLL |
| 514 | menu.next(); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 515 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 516 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 517 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 518 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 519 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 520 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 521 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 522 | |
| 523 | // Active next (6) |
| 524 | menu.next(); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 525 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 526 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 527 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 528 | expect(menu.shownItem(1).active()).toBe(true); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 529 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 530 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 531 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 532 | }); |
| 533 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 534 | it('should be prevable', function () { |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 535 | var menu = KorAP.HintMenu.create("cnx/", list); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 536 | menu.limit(3); |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 537 | expect(menu.show()).toBe(true); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 538 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 539 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 540 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 541 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 542 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 543 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 544 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 545 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 546 | |
| 547 | // Activate prev (1) - roll to bottom |
| 548 | menu.prev(); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 549 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 550 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 551 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 552 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 553 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Syntax</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 554 | expect(menu.shownItem(2).active()).toBe(true); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 555 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 556 | |
| 557 | // Activate prev (2) |
| 558 | menu.prev(); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 559 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 560 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 561 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 562 | expect(menu.shownItem(1).active()).toBe(true); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 563 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Syntax</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 564 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 565 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 566 | |
| 567 | // Activate prev (3) |
| 568 | menu.prev(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 569 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 570 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 571 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 572 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 573 | expect(menu.shownItem(2).name()).toEqual("Syntax"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 574 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 575 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 576 | |
| 577 | // Activate prev (4) |
| 578 | menu.prev(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 579 | expect(menu.shownItem(0).name()).toEqual("Lemma"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 580 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 581 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 582 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 583 | expect(menu.shownItem(2).name()).toEqual("Part-of-Speech"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 584 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 585 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 586 | |
| 587 | // Activate prev (5) |
| 588 | menu.prev(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 589 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 590 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 591 | expect(menu.shownItem(1).name()).toEqual("Lemma"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 592 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 593 | expect(menu.shownItem(2).name()).toEqual("Morphology"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 594 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 595 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 596 | |
| 597 | // Activate next (1) |
| 598 | menu.next(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 599 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 600 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 601 | expect(menu.shownItem(1).name()).toEqual("Lemma"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 602 | expect(menu.shownItem(1).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 603 | expect(menu.shownItem(2).name()).toEqual("Morphology"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 604 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 605 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 606 | |
| 607 | // Activate prev (6) |
| 608 | menu.prev(); |
| 609 | |
| 610 | // Activate prev (7) |
| 611 | menu.prev(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 612 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 613 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 614 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 615 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 616 | expect(menu.shownItem(2).name()).toEqual("Syntax"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 617 | expect(menu.shownItem(2).active()).toBe(true); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 618 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 619 | }); |
| 620 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 621 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 622 | it('should be navigatable and filterable (prefix = "o")', function () { |
| 623 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 624 | menu.limit(2); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 625 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 626 | expect(menu.prefix("o").show()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 627 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 628 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 629 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 630 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 631 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 632 | expect(menu.shownItem(1).active()).toBe(false); |
| 633 | expect(menu.shownItem(2)).toBe(undefined); |
| 634 | |
| 635 | // Next (1) |
| 636 | menu.next(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 637 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 638 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 639 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 640 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 641 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 642 | expect(menu.shownItem(1).active()).toBe(true); |
| 643 | expect(menu.shownItem(2)).toBe(undefined); |
| 644 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 645 | // Next (2) |
| 646 | menu.next(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 647 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 648 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 649 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 650 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 651 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 652 | expect(menu.shownItem(1).active()).toBe(true); |
| 653 | expect(menu.shownItem(2)).toBe(undefined); |
| 654 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 655 | // Next (3) - to prefix |
| 656 | menu.next(); |
| 657 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
| 658 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>"); |
| 659 | expect(menu.shownItem(0).active()).toBe(false); |
| 660 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
| 661 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>"); |
| 662 | expect(menu.shownItem(1).active()).toBe(false); |
| 663 | expect(menu.shownItem(2)).toBe(undefined); |
| 664 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 665 | menu.next(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 666 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 667 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 668 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 669 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 670 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>M<mark>o</mark>rph<mark>o</mark>l<mark>o</mark>gy</strong><span>Example 2</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 671 | expect(menu.shownItem(1).active()).toBe(false); |
| 672 | expect(menu.shownItem(2)).toBe(undefined); |
| 673 | }); |
| 674 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 675 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 676 | it('should be navigatable and filterable (prefix = "ex", "e")', function () { |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 677 | var menu = KorAP.HintMenu.create("cnx/", list); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 678 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 679 | menu.limit(2); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 680 | expect(menu.prefix("ex").show()).toBe(true); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 681 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 682 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 683 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 684 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 685 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 686 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 687 | expect(menu.shownItem(1).active()).toBe(false); |
| 688 | expect(menu.shownItem(2)).toBe(undefined); |
| 689 | |
| 690 | // Next (1) |
| 691 | menu.next(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 692 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 693 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 694 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 695 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 696 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 697 | expect(menu.shownItem(1).active()).toBe(true); |
| 698 | expect(menu.shownItem(2)).toBe(undefined); |
| 699 | |
| 700 | // Next (2) |
| 701 | menu.next(); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 702 | |
| 703 | expect(menu.prefix()).toEqual('ex'); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 704 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 705 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>"); |
| 706 | expect(menu.shownItem(0).active()).toBe(false); |
| 707 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 708 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 709 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 710 | expect(menu.shownItem(1).active()).toBe(false); |
| 711 | expect(menu.shownItem(2)).toBe(undefined); |
| 712 | |
| 713 | // Reset limit |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 714 | menu.limit(5); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 715 | |
| 716 | // Change show |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 717 | expect(menu.prefix("e").show()).toBe(true); |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 718 | expect(menu._prefix.active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 719 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 720 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 721 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 722 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 723 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 724 | expect(menu.shownItem(1).active()).toBe(false); |
| 725 | expect(menu.shownItem(2)).toBe(undefined); |
| 726 | |
| 727 | // Next (1) |
| 728 | menu.next(); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 729 | expect(menu._prefix.active()).toBe(false); |
| 730 | expect(menu.prefix()).toEqual('e'); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 731 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 732 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 733 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 734 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 735 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 736 | expect(menu.shownItem(1).active()).toBe(true); |
| 737 | expect(menu.shownItem(2)).toBe(undefined); |
| 738 | |
| 739 | // Next (2) |
| 740 | menu.next(); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 741 | expect(menu._prefix.active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 742 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 743 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
| 744 | expect(menu.shownItem(0).active()).toBe(false); |
| 745 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
| 746 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
| 747 | expect(menu.shownItem(1).active()).toBe(false); |
| 748 | expect(menu.shownItem(2)).toBe(undefined); |
| 749 | |
| 750 | // Next (3) |
| 751 | menu.next(); |
| 752 | expect(menu._prefix.active()).toBe(false); |
| 753 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
| 754 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 755 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 756 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 757 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 758 | expect(menu.shownItem(1).active()).toBe(false); |
| 759 | expect(menu.shownItem(2)).toBe(undefined); |
| 760 | }); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 761 | |
| 762 | |
| 763 | it('shouldn\'t be viewable with failing prefix', function () { |
| 764 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 765 | menu.limit(2); |
| 766 | expect(menu.prefix("exit").show()).toBe(false); |
| 767 | }); |
| 768 | |
| 769 | it('should be navigatable with prefix', function () { |
| 770 | var menu = KorAP.HintMenu.create("cnx/", demolist); |
| 771 | menu.limit(3); |
| 772 | |
| 773 | expect(menu.show()).toBe(true); |
| 774 | expect(menu.prefix()).toEqual(""); |
| 775 | |
| 776 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 777 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>"); |
| 778 | expect(menu.shownItem(0).active()).toBe(true); |
| 779 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 780 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>"); |
| 781 | expect(menu.shownItem(1).active()).toBe(false); |
| 782 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
| 783 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
| 784 | expect(menu.shownItem(2).active()).toBe(false); |
| 785 | expect(menu.shownItem(3)).toBe(undefined); |
| 786 | |
| 787 | menu._prefix.add('a'); |
| 788 | expect(menu.show()).toBe(true); |
| 789 | expect(menu.prefix()).toEqual("a"); |
| 790 | expect(menu.shownItem(0).name()).toEqual("Autor"); |
| 791 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>"); |
| 792 | |
| 793 | menu._prefix.add('u'); |
| 794 | expect(menu.show()).toBe(true); |
| 795 | expect(menu.prefix()).toEqual("au"); |
| 796 | expect(menu.shownItem(0).name()).toEqual("Autor"); |
| 797 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong><mark>Au</mark>tor</strong>"); |
| 798 | |
| 799 | menu._prefix.backspace(); |
| 800 | expect(menu.show()).toBe(true); |
| 801 | expect(menu.prefix()).toEqual("a"); |
| 802 | expect(menu.shownItem(0).name()).toEqual("Autor"); |
| 803 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>"); |
| 804 | |
| 805 | menu._prefix.backspace(); |
| 806 | expect(menu.show()).toBe(true); |
| 807 | expect(menu.prefix()).toEqual(""); |
| 808 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 809 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>"); |
| 810 | expect(menu.shownItem(0).active()).toBe(true); |
| 811 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 812 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>"); |
| 813 | expect(menu.shownItem(1).active()).toBe(false); |
| 814 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
| 815 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
| 816 | expect(menu.shownItem(2).active()).toBe(false); |
| 817 | expect(menu.shownItem(3)).toBe(undefined); |
| 818 | |
| 819 | // Forward |
| 820 | menu._prefix.backspace(); |
| 821 | expect(menu.show()).toBe(true); |
| 822 | expect(menu.prefix()).toEqual(""); |
| 823 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 824 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>"); |
| 825 | expect(menu.shownItem(0).active()).toBe(true); |
| 826 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 827 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>"); |
| 828 | expect(menu.shownItem(1).active()).toBe(false); |
| 829 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
| 830 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
| 831 | expect(menu.shownItem(2).active()).toBe(false); |
| 832 | |
| 833 | // Forward |
| 834 | menu.next(); |
| 835 | expect(menu.prefix()).toEqual(""); |
| 836 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 837 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>"); |
| 838 | expect(menu.shownItem(0).active()).toBe(false); |
| 839 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 840 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>"); |
| 841 | expect(menu.shownItem(1).active()).toBe(true); |
| 842 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
| 843 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
| 844 | expect(menu.shownItem(2).active()).toBe(false); |
| 845 | expect(menu.shownItem(3)).toBe(undefined); |
| 846 | |
| 847 | // Forward |
| 848 | menu.next(); |
| 849 | expect(menu.prefix()).toEqual(""); |
| 850 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 851 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>"); |
| 852 | expect(menu.shownItem(0).active()).toBe(false); |
| 853 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 854 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>"); |
| 855 | expect(menu.shownItem(1).active()).toBe(false); |
| 856 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
| 857 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
| 858 | expect(menu.shownItem(2).active()).toBe(true); |
| 859 | expect(menu.shownItem(3)).toBe(undefined); |
| 860 | |
| 861 | // Forward |
| 862 | menu.next(); |
| 863 | expect(menu.prefix()).toEqual(""); |
| 864 | expect(menu.shownItem(0).name()).toEqual("Untertitel"); |
| 865 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Untertitel</strong>"); |
| 866 | expect(menu.shownItem(0).active()).toBe(false); |
| 867 | expect(menu.shownItem(1).name()).toEqual("Veröffentlichungsdatum"); |
| 868 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
| 869 | expect(menu.shownItem(1).active()).toBe(false); |
| 870 | expect(menu.shownItem(2).name()).toEqual("Länge"); |
| 871 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Länge</strong>"); |
| 872 | expect(menu.shownItem(2).active()).toBe(true); |
| 873 | expect(menu.shownItem(3)).toBe(undefined); |
| 874 | |
| 875 | // Forward |
| 876 | menu.next(); |
| 877 | expect(menu.prefix()).toEqual(""); |
| 878 | expect(menu.shownItem(0).name()).toEqual("Veröffentlichungsdatum"); |
| 879 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
| 880 | expect(menu.shownItem(0).active()).toBe(false); |
| 881 | expect(menu.shownItem(1).name()).toEqual("Länge"); |
| 882 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Länge</strong>"); |
| 883 | expect(menu.shownItem(1).active()).toBe(false); |
| 884 | expect(menu.shownItem(2).name()).toEqual("Autor"); |
| 885 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Autor</strong>"); |
| 886 | expect(menu.shownItem(2).active()).toBe(true); |
| 887 | expect(menu.shownItem(3)).toBe(undefined); |
| 888 | |
| 889 | // Forward |
| 890 | menu.next(); |
| 891 | expect(menu.prefix()).toEqual(""); |
| 892 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 893 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>"); |
| 894 | expect(menu.shownItem(0).active()).toBe(true); |
| 895 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 896 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>"); |
| 897 | expect(menu.shownItem(1).active()).toBe(false); |
| 898 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
| 899 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
| 900 | expect(menu.shownItem(2).active()).toBe(false); |
| 901 | |
| 902 | }); |
| 903 | |
| 904 | |
| 905 | it('should be navigatable with a prefix (1)', function () { |
| 906 | var menu = KorAP.HintMenu.create("cnx/", demolist); |
| 907 | menu.limit(3); |
| 908 | |
| 909 | expect(menu.show()).toBe(true); |
| 910 | expect(menu.prefix()).toEqual(""); |
| 911 | |
| 912 | menu.prefix('el'); |
| 913 | expect(menu.show()).toBe(true); |
| 914 | |
| 915 | expect(menu.prefix()).toEqual("el"); |
| 916 | expect(menu._prefix.active()).toEqual(false); |
| 917 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 918 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
| 919 | expect(menu.shownItem(0).active()).toBe(true); |
| 920 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 921 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
| 922 | expect(menu.shownItem(1).active()).toBe(false); |
| 923 | expect(menu.shownItem(2)).toBe(undefined); |
| 924 | |
| 925 | // Forward |
| 926 | menu.next(); |
| 927 | expect(menu.prefix()).toEqual("el"); |
| 928 | expect(menu._prefix.active()).toEqual(false); |
| 929 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 930 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
| 931 | expect(menu.shownItem(0).active()).toBe(false); |
| 932 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 933 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
| 934 | expect(menu.shownItem(1).active()).toBe(true); |
| 935 | expect(menu.shownItem(2)).toBe(undefined); |
| 936 | |
| 937 | // Forward |
| 938 | menu.next(); |
| 939 | expect(menu.prefix()).toEqual("el"); |
| 940 | expect(menu._prefix.active()).toEqual(true); |
| 941 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 942 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
| 943 | expect(menu.shownItem(0).active()).toBe(false); |
| 944 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 945 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
| 946 | expect(menu.shownItem(1).active()).toBe(false); |
| 947 | expect(menu.shownItem(2)).toBe(undefined); |
| 948 | |
| 949 | |
| 950 | // Backward |
| 951 | menu.prev(); |
| 952 | expect(menu.prefix()).toEqual("el"); |
| 953 | expect(menu._prefix.active()).toEqual(false); |
| 954 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 955 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
| 956 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 2d21075 | 2015-03-09 19:01:15 +0000 | [diff] [blame] | 957 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 958 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 959 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
| 960 | expect(menu.shownItem(1).active()).toBe(true); |
| 961 | expect(menu.shownItem(2)).toBe(undefined); |
| 962 | }); |
| 963 | |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 964 | |
Nils Diewald | 2d21075 | 2015-03-09 19:01:15 +0000 | [diff] [blame] | 965 | it('should be navigatable with a prefix (2)', function () { |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 966 | var menu = KorAP.HintMenu.create("cnx/", demolist); |
| 967 | menu.limit(3); |
| 968 | expect(menu.show()).toBe(true); |
| 969 | expect(menu.prefix()).toEqual(""); |
| 970 | menu.prefix('el'); |
| 971 | expect(menu.show()).toBe(true); |
| 972 | |
| 973 | expect(menu.prefix()).toEqual("el"); |
| 974 | expect(menu._prefix.active()).toEqual(false); |
| 975 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 976 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
| 977 | expect(menu.shownItem(0).active()).toBe(true); |
| 978 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 979 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
| 980 | expect(menu.shownItem(1).active()).toBe(false); |
| 981 | expect(menu.shownItem(2)).toBe(undefined); |
| 982 | |
| 983 | // Backward |
| 984 | menu.prev(); |
| 985 | expect(menu._prefix.active()).toEqual(true); |
Nils Diewald | 2d21075 | 2015-03-09 19:01:15 +0000 | [diff] [blame] | 986 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 987 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 988 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
| 989 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 2d21075 | 2015-03-09 19:01:15 +0000 | [diff] [blame] | 990 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 991 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 992 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
| 993 | expect(menu.shownItem(1).active()).toBe(false); |
| 994 | expect(menu.shownItem(2)).toBe(undefined); |
| 995 | |
| 996 | // Backward |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 997 | menu.prev(); |
| 998 | expect(menu._prefix.active()).toEqual(false); |
| 999 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 1000 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
| 1001 | expect(menu.shownItem(0).active()).toBe(false); |
| 1002 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 1003 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
| 1004 | expect(menu.shownItem(1).active()).toBe(true); |
| 1005 | expect(menu.shownItem(2)).toBe(undefined); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 1006 | }); |
| 1007 | |
Nils Diewald | e8518f8 | 2015-03-18 22:41:49 +0000 | [diff] [blame] | 1008 | it('should be navigatable with a prefix (3)', function () { |
| 1009 | var menu = KorAP.HintMenu.create("cnx/", demolist); |
| 1010 | menu.limit(3); |
| 1011 | expect(menu.show()).toBe(true); |
| 1012 | expect(menu.prefix()).toEqual(""); |
| 1013 | menu.prefix('el'); |
| 1014 | expect(menu.show()).toBe(true); |
| 1015 | |
| 1016 | expect(menu.prefix()).toEqual("el"); |
| 1017 | expect(menu._prefix.active()).toEqual(false); |
| 1018 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 1019 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
| 1020 | expect(menu.shownItem(0).active()).toBe(true); |
| 1021 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 1022 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
| 1023 | expect(menu.shownItem(1).active()).toBe(false); |
| 1024 | expect(menu.shownItem(2)).toBe(undefined); |
| 1025 | |
| 1026 | // Backward |
| 1027 | menu.prev(); |
| 1028 | expect(menu._prefix.active()).toEqual(true); |
| 1029 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 1030 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
| 1031 | expect(menu.shownItem(0).active()).toBe(false); |
| 1032 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 1033 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
| 1034 | expect(menu.shownItem(1).active()).toBe(false); |
| 1035 | expect(menu.shownItem(2)).toBe(undefined); |
| 1036 | |
| 1037 | |
| 1038 | // Forward |
| 1039 | menu.next(); |
| 1040 | expect(menu.prefix()).toEqual("el"); |
| 1041 | expect(menu._prefix.active()).toEqual(false); |
| 1042 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 1043 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
| 1044 | expect(menu.shownItem(0).active()).toBe(true); |
| 1045 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 1046 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
| 1047 | expect(menu.shownItem(1).active()).toBe(false); |
| 1048 | expect(menu.shownItem(2)).toBe(undefined); |
| 1049 | |
| 1050 | }); |
| 1051 | |
Nils Diewald | 6e43ffd | 2015-03-25 18:55:39 +0000 | [diff] [blame^] | 1052 | xit('should be page downable'); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 1053 | xit('should be page upable'); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 1054 | }); |