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