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 | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 331 | it('should be initializable', function () { |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 332 | var list = [ |
| 333 | ["Constituency"], |
| 334 | ["Lemma"], |
| 335 | ["Morphology"], |
| 336 | ["Part-of-Speech"], |
| 337 | ["Syntax"] |
| 338 | ]; |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 339 | |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 340 | var menu = KorAP.OwnMenu.create(list); |
| 341 | expect(menu.itemClass()).toEqual(KorAP.OwnMenuItem); |
| 342 | expect(menu.element().nodeName).toEqual('UL'); |
| 343 | expect(menu.element().style.opacity).toEqual("0"); |
| 344 | expect(menu.limit()).toEqual(8); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 345 | |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 346 | menu.limit(9); |
| 347 | expect(menu.limit()).toEqual(9); |
| 348 | |
| 349 | menu.limit(8); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 350 | |
| 351 | // view |
| 352 | menu.show(); |
| 353 | |
| 354 | // First element in list |
| 355 | expect(menu.item(0).active()).toBe(true); |
| 356 | expect(menu.item(0).noMore()).toBe(true); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 357 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 358 | // Middle element in list |
| 359 | expect(menu.item(2).active()).toBe(false); |
| 360 | expect(menu.item(2).noMore()).toBe(false); |
| 361 | |
| 362 | // Last element in list |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 363 | expect(menu.item(menu.length() - 1).active()).toBe(false); |
| 364 | expect(menu.item(menu.length() - 1).noMore()).toBe(true); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 365 | }); |
| 366 | |
| 367 | it('should be visible', function () { |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 368 | var menu = KorAP.HintMenu.create("cnx/", list); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 369 | expect(menu.delete()).toBe(undefined); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 370 | menu.limit(3); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 371 | |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 372 | expect(menu.show()).toBe(true); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 373 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 374 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
| 375 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>"); |
| 376 | expect(menu.element().childNodes[2].getAttribute("data-action")).toEqual("l="); |
| 377 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 378 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 379 | |
| 380 | // Check boundaries |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 381 | expect(menu.element().childNodes[1].classList.contains("no-more")).toBe(true); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 382 | expect(menu.element().childNodes[2].classList.contains("no-more")).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 383 | expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(false); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 384 | }); |
| 385 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 386 | it('should be filterable', function () { |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 387 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 388 | menu.limit(3); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 389 | expect(menu.prefix("o").show()).toBe(true); |
| 390 | expect(menu.element().childNodes[0].innerHTML).toEqual("o"); |
| 391 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
| 392 | 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>"); |
| 393 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>"); |
| 394 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 395 | |
| 396 | // Check boundaries |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 397 | expect(menu.element().childNodes[1].classList.contains("no-more")).toBe(true); |
| 398 | expect(menu.element().childNodes[2].classList.contains("no-more")).toBe(false); |
| 399 | expect(menu.element().childNodes[3].classList.contains("no-more")).toBe(true); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 400 | |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 401 | menu.limit(2); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 402 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 403 | expect(menu.prefix("o").show()).toBe(true); |
| 404 | expect(menu.element().childNodes[0].innerHTML).toEqual("o"); |
| 405 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
| 406 | 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>"); |
| 407 | expect(menu.element().childNodes[3]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 408 | |
| 409 | // Check boundaries |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 410 | expect(menu.element().childNodes[1].classList.contains("no-more")).toBe(true); |
| 411 | expect(menu.element().childNodes[2].classList.contains("no-more")).toBe(false); |
| 412 | expect(menu.element().childNodes[3]).toBe(undefined); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 413 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 414 | expect(menu.prefix("e").show()).toBe(true); |
| 415 | expect(menu.element().childNodes[0].innerHTML).toEqual("e"); |
| 416 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
| 417 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
| 418 | expect(menu.element().childNodes[3]).toBe(undefined); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 419 | |
| 420 | menu.limit(5); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 421 | expect(menu.prefix("a").show()).toBe(true); |
| 422 | expect(menu.element().childNodes[0].innerHTML).toEqual("a"); |
| 423 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constituency</strong><span>Ex<mark>a</mark>mple 1</span>"); |
| 424 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemm<mark>a</mark></strong>"); |
| 425 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Morphology</strong><span>Ex<mark>a</mark>mple 2</span>"); |
| 426 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>P<mark>a</mark>rt-of-Speech</strong>"); |
| 427 | expect(menu.element().childNodes[5].innerHTML).toEqual("<strong>Synt<mark>a</mark>x</strong>"); |
| 428 | expect(menu.element().childNodes[6]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 429 | }); |
| 430 | |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 431 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 432 | it('should be nextable', function () { |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 433 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 434 | |
| 435 | // Show only 3 items |
| 436 | menu.limit(3); |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 437 | expect(menu.show()).toBe(true); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 438 | 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] | 439 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 440 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 441 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 442 | 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] | 443 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 444 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 445 | |
| 446 | // Activate next (1) |
| 447 | menu.next(); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 448 | 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] | 449 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 450 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 451 | expect(menu.shownItem(1).active()).toBe(true); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 452 | 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] | 453 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 454 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 455 | |
| 456 | // Activate next (2) |
| 457 | menu.next(); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 458 | 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] | 459 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 460 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 461 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 462 | 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] | 463 | expect(menu.shownItem(2).active()).toBe(true); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 464 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 465 | |
| 466 | // Activate next (3) |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 467 | // scroll! |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 468 | menu.next(); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 469 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 470 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 471 | 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] | 472 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 473 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 474 | expect(menu.shownItem(2).active()).toBe(true); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 475 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 476 | |
| 477 | // Activate next (4) |
| 478 | menu.next(); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 479 | 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] | 480 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 481 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 482 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 483 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Syntax</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 484 | expect(menu.shownItem(2).active()).toBe(true); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 485 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 486 | |
| 487 | // Activate next (5) - ROLL |
| 488 | menu.next(); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 489 | 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] | 490 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 491 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 492 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 493 | 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] | 494 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 495 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 496 | |
| 497 | // Active next (6) |
| 498 | menu.next(); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 499 | 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] | 500 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 501 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 502 | expect(menu.shownItem(1).active()).toBe(true); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 503 | 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] | 504 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 505 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 506 | }); |
| 507 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 508 | it('should be prevable', function () { |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 509 | var menu = KorAP.HintMenu.create("cnx/", list); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 510 | menu.limit(3); |
Nils Diewald | 59c02fc | 2015-03-07 01:29:09 +0000 | [diff] [blame] | 511 | expect(menu.show()).toBe(true); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 512 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 513 | 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] | 514 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 515 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 516 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 517 | 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] | 518 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 519 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 520 | |
| 521 | // Activate prev (1) - roll to bottom |
| 522 | menu.prev(); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 523 | 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] | 524 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 525 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 526 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 527 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Syntax</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 528 | expect(menu.shownItem(2).active()).toBe(true); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 529 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 530 | |
| 531 | // Activate prev (2) |
| 532 | menu.prev(); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 533 | 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] | 534 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 535 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 536 | expect(menu.shownItem(1).active()).toBe(true); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 537 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Syntax</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 538 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 539 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 540 | |
| 541 | // Activate prev (3) |
| 542 | menu.prev(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 543 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 544 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 545 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 546 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 547 | expect(menu.shownItem(2).name()).toEqual("Syntax"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 548 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 549 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 550 | |
| 551 | // Activate prev (4) |
| 552 | menu.prev(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 553 | expect(menu.shownItem(0).name()).toEqual("Lemma"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 554 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 555 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 556 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 557 | expect(menu.shownItem(2).name()).toEqual("Part-of-Speech"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 558 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 559 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 560 | |
| 561 | // Activate prev (5) |
| 562 | menu.prev(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 563 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 564 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 565 | expect(menu.shownItem(1).name()).toEqual("Lemma"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 566 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 567 | expect(menu.shownItem(2).name()).toEqual("Morphology"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 568 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 569 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 570 | |
| 571 | // Activate next (1) |
| 572 | menu.next(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 573 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 574 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 575 | expect(menu.shownItem(1).name()).toEqual("Lemma"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 576 | expect(menu.shownItem(1).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 577 | expect(menu.shownItem(2).name()).toEqual("Morphology"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 578 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 579 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 580 | |
| 581 | // Activate prev (6) |
| 582 | menu.prev(); |
| 583 | |
| 584 | // Activate prev (7) |
| 585 | menu.prev(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 586 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 587 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 588 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 589 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 590 | expect(menu.shownItem(2).name()).toEqual("Syntax"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 591 | expect(menu.shownItem(2).active()).toBe(true); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 592 | expect(menu.element().childNodes[4]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 593 | }); |
| 594 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 595 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 596 | it('should be navigatable and filterable (prefix = "o")', function () { |
| 597 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 598 | menu.limit(2); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 599 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 600 | expect(menu.prefix("o").show()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 601 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 602 | 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] | 603 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 604 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 605 | 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] | 606 | expect(menu.shownItem(1).active()).toBe(false); |
| 607 | expect(menu.shownItem(2)).toBe(undefined); |
| 608 | |
| 609 | // Next (1) |
| 610 | menu.next(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 611 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 612 | 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] | 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("Morphology"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 615 | 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] | 616 | expect(menu.shownItem(1).active()).toBe(true); |
| 617 | expect(menu.shownItem(2)).toBe(undefined); |
| 618 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 619 | // Next (2) |
| 620 | menu.next(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 621 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 622 | 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] | 623 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 624 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 625 | 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] | 626 | expect(menu.shownItem(1).active()).toBe(true); |
| 627 | expect(menu.shownItem(2)).toBe(undefined); |
| 628 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 629 | // Next (3) - to prefix |
| 630 | menu.next(); |
| 631 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
| 632 | 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>"); |
| 633 | expect(menu.shownItem(0).active()).toBe(false); |
| 634 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
| 635 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>"); |
| 636 | expect(menu.shownItem(1).active()).toBe(false); |
| 637 | expect(menu.shownItem(2)).toBe(undefined); |
| 638 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 639 | menu.next(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 640 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 641 | 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] | 642 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 643 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 644 | 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] | 645 | expect(menu.shownItem(1).active()).toBe(false); |
| 646 | expect(menu.shownItem(2)).toBe(undefined); |
| 647 | }); |
| 648 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 649 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 650 | it('should be navigatable and filterable (prefix = "ex", "e")', function () { |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 651 | var menu = KorAP.HintMenu.create("cnx/", list); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 652 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 653 | menu.limit(2); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 654 | expect(menu.prefix("ex").show()).toBe(true); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 655 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 656 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 657 | 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] | 658 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 659 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 660 | 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] | 661 | expect(menu.shownItem(1).active()).toBe(false); |
| 662 | expect(menu.shownItem(2)).toBe(undefined); |
| 663 | |
| 664 | // Next (1) |
| 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>Constituency</strong><span><mark>Ex</mark>ample 1</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 668 | expect(menu.shownItem(0).active()).toBe(false); |
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>Morphology</strong><span><mark>Ex</mark>ample 2</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 671 | expect(menu.shownItem(1).active()).toBe(true); |
| 672 | expect(menu.shownItem(2)).toBe(undefined); |
| 673 | |
| 674 | // Next (2) |
| 675 | menu.next(); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 676 | |
| 677 | expect(menu.prefix()).toEqual('ex'); |
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>"); |
| 680 | expect(menu.shownItem(0).active()).toBe(false); |
| 681 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 682 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 683 | 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] | 684 | expect(menu.shownItem(1).active()).toBe(false); |
| 685 | expect(menu.shownItem(2)).toBe(undefined); |
| 686 | |
| 687 | // Reset limit |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 688 | menu.limit(5); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 689 | |
| 690 | // Change show |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 691 | expect(menu.prefix("e").show()).toBe(true); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 692 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 693 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 694 | 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] | 695 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 696 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 697 | 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] | 698 | expect(menu.shownItem(1).active()).toBe(false); |
| 699 | expect(menu.shownItem(2)).toBe(undefined); |
| 700 | |
| 701 | // Next (1) |
| 702 | menu.next(); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 703 | expect(menu._prefix.active()).toBe(false); |
| 704 | expect(menu.prefix()).toEqual('e'); |
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(false); |
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(true); |
| 711 | expect(menu.shownItem(2)).toBe(undefined); |
| 712 | |
| 713 | // Next (2) |
| 714 | menu.next(); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 715 | expect(menu._prefix.active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 716 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 717 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
| 718 | expect(menu.shownItem(0).active()).toBe(false); |
| 719 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
| 720 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
| 721 | expect(menu.shownItem(1).active()).toBe(false); |
| 722 | expect(menu.shownItem(2)).toBe(undefined); |
| 723 | |
| 724 | // Next (3) |
| 725 | menu.next(); |
| 726 | expect(menu._prefix.active()).toBe(false); |
| 727 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
| 728 | 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] | 729 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 730 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 731 | 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] | 732 | expect(menu.shownItem(1).active()).toBe(false); |
| 733 | expect(menu.shownItem(2)).toBe(undefined); |
| 734 | }); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 735 | |
| 736 | |
| 737 | it('shouldn\'t be viewable with failing prefix', function () { |
| 738 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 739 | menu.limit(2); |
| 740 | expect(menu.prefix("exit").show()).toBe(false); |
| 741 | }); |
| 742 | |
| 743 | it('should be navigatable with prefix', function () { |
| 744 | var menu = KorAP.HintMenu.create("cnx/", demolist); |
| 745 | menu.limit(3); |
| 746 | |
| 747 | expect(menu.show()).toBe(true); |
| 748 | expect(menu.prefix()).toEqual(""); |
| 749 | |
| 750 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 751 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>"); |
| 752 | expect(menu.shownItem(0).active()).toBe(true); |
| 753 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 754 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>"); |
| 755 | expect(menu.shownItem(1).active()).toBe(false); |
| 756 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
| 757 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
| 758 | expect(menu.shownItem(2).active()).toBe(false); |
| 759 | expect(menu.shownItem(3)).toBe(undefined); |
| 760 | |
| 761 | menu._prefix.add('a'); |
| 762 | expect(menu.show()).toBe(true); |
| 763 | expect(menu.prefix()).toEqual("a"); |
| 764 | expect(menu.shownItem(0).name()).toEqual("Autor"); |
| 765 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong><mark>A</mark>utor</strong>"); |
| 766 | |
| 767 | menu._prefix.add('u'); |
| 768 | expect(menu.show()).toBe(true); |
| 769 | expect(menu.prefix()).toEqual("au"); |
| 770 | expect(menu.shownItem(0).name()).toEqual("Autor"); |
| 771 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong><mark>Au</mark>tor</strong>"); |
| 772 | |
| 773 | menu._prefix.backspace(); |
| 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.backspace(); |
| 780 | expect(menu.show()).toBe(true); |
| 781 | expect(menu.prefix()).toEqual(""); |
| 782 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 783 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>"); |
| 784 | expect(menu.shownItem(0).active()).toBe(true); |
| 785 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 786 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>"); |
| 787 | expect(menu.shownItem(1).active()).toBe(false); |
| 788 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
| 789 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
| 790 | expect(menu.shownItem(2).active()).toBe(false); |
| 791 | expect(menu.shownItem(3)).toBe(undefined); |
| 792 | |
| 793 | // Forward |
| 794 | menu._prefix.backspace(); |
| 795 | expect(menu.show()).toBe(true); |
| 796 | expect(menu.prefix()).toEqual(""); |
| 797 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 798 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>"); |
| 799 | expect(menu.shownItem(0).active()).toBe(true); |
| 800 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 801 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>"); |
| 802 | expect(menu.shownItem(1).active()).toBe(false); |
| 803 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
| 804 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
| 805 | expect(menu.shownItem(2).active()).toBe(false); |
| 806 | |
| 807 | // Forward |
| 808 | menu.next(); |
| 809 | expect(menu.prefix()).toEqual(""); |
| 810 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 811 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>"); |
| 812 | expect(menu.shownItem(0).active()).toBe(false); |
| 813 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 814 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>"); |
| 815 | expect(menu.shownItem(1).active()).toBe(true); |
| 816 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
| 817 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
| 818 | expect(menu.shownItem(2).active()).toBe(false); |
| 819 | expect(menu.shownItem(3)).toBe(undefined); |
| 820 | |
| 821 | // Forward |
| 822 | menu.next(); |
| 823 | expect(menu.prefix()).toEqual(""); |
| 824 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 825 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>"); |
| 826 | expect(menu.shownItem(0).active()).toBe(false); |
| 827 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 828 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>"); |
| 829 | expect(menu.shownItem(1).active()).toBe(false); |
| 830 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
| 831 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
| 832 | expect(menu.shownItem(2).active()).toBe(true); |
| 833 | expect(menu.shownItem(3)).toBe(undefined); |
| 834 | |
| 835 | // Forward |
| 836 | menu.next(); |
| 837 | expect(menu.prefix()).toEqual(""); |
| 838 | expect(menu.shownItem(0).name()).toEqual("Untertitel"); |
| 839 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Untertitel</strong>"); |
| 840 | expect(menu.shownItem(0).active()).toBe(false); |
| 841 | expect(menu.shownItem(1).name()).toEqual("Veröffentlichungsdatum"); |
| 842 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
| 843 | expect(menu.shownItem(1).active()).toBe(false); |
| 844 | expect(menu.shownItem(2).name()).toEqual("Länge"); |
| 845 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Länge</strong>"); |
| 846 | expect(menu.shownItem(2).active()).toBe(true); |
| 847 | expect(menu.shownItem(3)).toBe(undefined); |
| 848 | |
| 849 | // Forward |
| 850 | menu.next(); |
| 851 | expect(menu.prefix()).toEqual(""); |
| 852 | expect(menu.shownItem(0).name()).toEqual("Veröffentlichungsdatum"); |
| 853 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
| 854 | expect(menu.shownItem(0).active()).toBe(false); |
| 855 | expect(menu.shownItem(1).name()).toEqual("Länge"); |
| 856 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Länge</strong>"); |
| 857 | expect(menu.shownItem(1).active()).toBe(false); |
| 858 | expect(menu.shownItem(2).name()).toEqual("Autor"); |
| 859 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Autor</strong>"); |
| 860 | expect(menu.shownItem(2).active()).toBe(true); |
| 861 | expect(menu.shownItem(3)).toBe(undefined); |
| 862 | |
| 863 | // Forward |
| 864 | menu.next(); |
| 865 | expect(menu.prefix()).toEqual(""); |
| 866 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 867 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Titel</strong>"); |
| 868 | expect(menu.shownItem(0).active()).toBe(true); |
| 869 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 870 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertitel</strong>"); |
| 871 | expect(menu.shownItem(1).active()).toBe(false); |
| 872 | expect(menu.shownItem(2).name()).toEqual("Veröffentlichungsdatum"); |
| 873 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>Veröffentlichungsdatum</strong>"); |
| 874 | expect(menu.shownItem(2).active()).toBe(false); |
| 875 | |
| 876 | }); |
| 877 | |
| 878 | |
| 879 | it('should be navigatable with a prefix (1)', function () { |
| 880 | var menu = KorAP.HintMenu.create("cnx/", demolist); |
| 881 | menu.limit(3); |
| 882 | |
| 883 | expect(menu.show()).toBe(true); |
| 884 | expect(menu.prefix()).toEqual(""); |
| 885 | |
| 886 | menu.prefix('el'); |
| 887 | expect(menu.show()).toBe(true); |
| 888 | |
| 889 | expect(menu.prefix()).toEqual("el"); |
| 890 | expect(menu._prefix.active()).toEqual(false); |
| 891 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 892 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
| 893 | expect(menu.shownItem(0).active()).toBe(true); |
| 894 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 895 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
| 896 | expect(menu.shownItem(1).active()).toBe(false); |
| 897 | expect(menu.shownItem(2)).toBe(undefined); |
| 898 | |
| 899 | // Forward |
| 900 | menu.next(); |
| 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(false); |
| 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(true); |
| 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(true); |
| 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(false); |
| 921 | expect(menu.shownItem(2)).toBe(undefined); |
| 922 | |
| 923 | |
| 924 | // Backward |
| 925 | menu.prev(); |
| 926 | expect(menu.prefix()).toEqual("el"); |
| 927 | expect(menu._prefix.active()).toEqual(false); |
| 928 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 929 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
| 930 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 2d21075 | 2015-03-09 19:01:15 +0000 | [diff] [blame^] | 931 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 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 | |
Nils Diewald | 2d21075 | 2015-03-09 19:01:15 +0000 | [diff] [blame^] | 938 | it('should be navigatable with a prefix (2)', function () { |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 939 | var menu = KorAP.HintMenu.create("cnx/", demolist); |
| 940 | menu.limit(3); |
| 941 | expect(menu.show()).toBe(true); |
| 942 | expect(menu.prefix()).toEqual(""); |
| 943 | menu.prefix('el'); |
| 944 | expect(menu.show()).toBe(true); |
| 945 | |
Nils Diewald | 2d21075 | 2015-03-09 19:01:15 +0000 | [diff] [blame^] | 946 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 947 | expect(menu.prefix()).toEqual("el"); |
| 948 | expect(menu._prefix.active()).toEqual(false); |
| 949 | expect(menu.shownItem(0).name()).toEqual("Titel"); |
| 950 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Tit<mark>el</mark></strong>"); |
| 951 | expect(menu.shownItem(0).active()).toBe(true); |
| 952 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 953 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
| 954 | expect(menu.shownItem(1).active()).toBe(false); |
| 955 | expect(menu.shownItem(2)).toBe(undefined); |
| 956 | |
| 957 | // Backward |
| 958 | menu.prev(); |
| 959 | expect(menu._prefix.active()).toEqual(true); |
Nils Diewald | 2d21075 | 2015-03-09 19:01:15 +0000 | [diff] [blame^] | 960 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 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(false); |
Nils Diewald | 2d21075 | 2015-03-09 19:01:15 +0000 | [diff] [blame^] | 964 | |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 965 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 966 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
| 967 | expect(menu.shownItem(1).active()).toBe(false); |
| 968 | expect(menu.shownItem(2)).toBe(undefined); |
| 969 | |
| 970 | // Backward |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 971 | menu.prev(); |
| 972 | expect(menu._prefix.active()).toEqual(false); |
| 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); |
| 976 | expect(menu.shownItem(1).name()).toEqual("Untertitel"); |
| 977 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Untertit<mark>el</mark></strong>"); |
| 978 | expect(menu.shownItem(1).active()).toBe(true); |
| 979 | expect(menu.shownItem(2)).toBe(undefined); |
Nils Diewald | 5975d70 | 2015-03-09 17:45:42 +0000 | [diff] [blame] | 980 | }); |
| 981 | |
| 982 | xit('should be page downable'); |
| 983 | xit('should be page upable'); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 984 | }); |