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) |
| 29 | ._init(KorAP.OwnMenuItem, params); |
| 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) |
| 102 | ._init(KorAP.HintMenuItem, params); |
| 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 | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 323 | it('should be initializable', function () { |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 324 | var list = [ |
| 325 | ["Constituency"], |
| 326 | ["Lemma"], |
| 327 | ["Morphology"], |
| 328 | ["Part-of-Speech"], |
| 329 | ["Syntax"] |
| 330 | ]; |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 331 | |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 332 | var menu = KorAP.OwnMenu.create(list); |
| 333 | expect(menu.itemClass()).toEqual(KorAP.OwnMenuItem); |
| 334 | expect(menu.element().nodeName).toEqual('UL'); |
| 335 | expect(menu.element().style.opacity).toEqual("0"); |
| 336 | expect(menu.limit()).toEqual(8); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 337 | |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 338 | menu.limit(9); |
| 339 | expect(menu.limit()).toEqual(9); |
| 340 | |
| 341 | menu.limit(8); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 342 | |
| 343 | // view |
| 344 | menu.show(); |
| 345 | |
| 346 | // First element in list |
| 347 | expect(menu.item(0).active()).toBe(true); |
| 348 | expect(menu.item(0).noMore()).toBe(true); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 349 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 350 | // Middle element in list |
| 351 | expect(menu.item(2).active()).toBe(false); |
| 352 | expect(menu.item(2).noMore()).toBe(false); |
| 353 | |
| 354 | // Last element in list |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 355 | expect(menu.item(menu.length() - 1).active()).toBe(false); |
| 356 | expect(menu.item(menu.length() - 1).noMore()).toBe(true); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 357 | }); |
| 358 | |
| 359 | it('should be visible', function () { |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 360 | var menu = KorAP.HintMenu.create("cnx/", list); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 361 | expect(menu.delete()).toBe(undefined); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 362 | menu.limit(3); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 363 | |
| 364 | expect(menu.show()).toBe(undefined); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 365 | expect(menu.element().firstChild.innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
| 366 | |
| 367 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
| 368 | expect(menu.element().childNodes[1].getAttribute("data-action")).toEqual("l="); |
| 369 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
| 370 | expect(menu.element().childNodes[3]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 371 | |
| 372 | // Check boundaries |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 373 | expect(menu.element().childNodes[0].classList.contains("no-more")).toBe(true); |
| 374 | expect(menu.element().childNodes[1].classList.contains("no-more")).toBe(false); |
| 375 | expect(menu.element().childNodes[2].classList.contains("no-more")).toBe(false); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 376 | }); |
| 377 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 378 | it('should be filterable', function () { |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 379 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 380 | menu.limit(3); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 381 | |
| 382 | expect(menu.show("o")).toBe(undefined); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 383 | expect(menu.element().childNodes[0].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
| 384 | 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>"); |
| 385 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>"); |
| 386 | expect(menu.element().childNodes[3]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 387 | |
| 388 | // Check boundaries |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 389 | expect(menu.element().childNodes[0].classList.contains("no-more")).toBe(true); |
| 390 | expect(menu.element().childNodes[1].classList.contains("no-more")).toBe(false); |
| 391 | expect(menu.element().childNodes[2].classList.contains("no-more")).toBe(true); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 392 | |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 393 | menu.limit(2); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 394 | |
| 395 | expect(menu.show("o")).toBe(undefined); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 396 | expect(menu.element().childNodes[0].innerHTML).toEqual("<strong>C<mark>o</mark>nstituency</strong><span>Example 1</span>"); |
| 397 | 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>"); |
| 398 | expect(menu.element().childNodes[2]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 399 | |
| 400 | // Check boundaries |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 401 | expect(menu.element().childNodes[0].classList.contains("no-more")).toBe(true); |
| 402 | expect(menu.element().childNodes[1].classList.contains("no-more")).toBe(false); |
| 403 | expect(menu.element().childNodes[2]).toBe(undefined); |
| 404 | |
| 405 | expect(menu.show("e")).toBe(undefined); |
| 406 | expect(menu.element().childNodes[0].innerHTML).toEqual("<strong>Constitu<mark>e</mark>ncy</strong><span><mark>E</mark>xampl<mark>e</mark> 1</span>"); |
| 407 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>E</mark>xampl<mark>e</mark> 2</span>"); |
| 408 | expect(menu.element().childNodes[2]).toBe(undefined); |
| 409 | |
| 410 | menu.limit(5); |
| 411 | |
| 412 | expect(menu.show("a")).toBe(undefined); |
| 413 | expect(menu.element().childNodes[0].innerHTML).toEqual("<strong>Constituency</strong><span>Ex<mark>a</mark>mple 1</span>"); |
| 414 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Lemm<mark>a</mark></strong>"); |
| 415 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Morphology</strong><span>Ex<mark>a</mark>mple 2</span>"); |
| 416 | expect(menu.element().childNodes[3].innerHTML).toEqual("<strong>P<mark>a</mark>rt-of-Speech</strong>"); |
| 417 | expect(menu.element().childNodes[4].innerHTML).toEqual("<strong>Synt<mark>a</mark>x</strong>"); |
| 418 | expect(menu.element().childNodes[5]).toBe(undefined); |
| 419 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 420 | }); |
| 421 | |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 422 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 423 | it('should be nextable', function () { |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 424 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 425 | |
| 426 | // Show only 3 items |
| 427 | menu.limit(3); |
| 428 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 429 | expect(menu.show()).toBe(undefined); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 430 | expect(menu.element().childNodes[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 431 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 432 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 433 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 434 | 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] | 435 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 436 | expect(menu.element().childNodes[3]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 437 | |
| 438 | // Activate next (1) |
| 439 | menu.next(); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 440 | expect(menu.element().childNodes[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 441 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 442 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 443 | expect(menu.shownItem(1).active()).toBe(true); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 444 | 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] | 445 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 446 | expect(menu.element().childNodes[3]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 447 | |
| 448 | // Activate next (2) |
| 449 | menu.next(); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 450 | expect(menu.element().childNodes[0].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(false); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 452 | expect(menu.element().childNodes[1].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 | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 454 | 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] | 455 | expect(menu.shownItem(2).active()).toBe(true); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 456 | expect(menu.element().childNodes[3]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 457 | |
| 458 | // Activate next (3) |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 459 | // scroll! |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 460 | menu.next(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 461 | expect(menu.element().childNodes[0].innerHTML).toEqual("<strong>Lemma</strong>"); |
| 462 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 463 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 464 | 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] | 465 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 466 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 467 | expect(menu.shownItem(2).active()).toBe(true); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 468 | expect(menu.element().childNodes[3]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 469 | |
| 470 | // Activate next (4) |
| 471 | menu.next(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 472 | expect(menu.element().childNodes[0].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 473 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 474 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 475 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 476 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Syntax</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 477 | expect(menu.shownItem(2).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 478 | expect(menu.element().childNodes[3]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 479 | |
| 480 | // Activate next (5) - ROLL |
| 481 | menu.next(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 482 | expect(menu.element().childNodes[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 483 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 484 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 485 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 486 | 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] | 487 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 488 | expect(menu.element().childNodes[3]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 489 | |
| 490 | // Active next (6) |
| 491 | menu.next(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 492 | expect(menu.element().childNodes[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 493 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 494 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 495 | expect(menu.shownItem(1).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 496 | 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] | 497 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 498 | expect(menu.element().childNodes[3]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 499 | }); |
| 500 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 501 | it('should be prevable', function () { |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 502 | var menu = KorAP.HintMenu.create("cnx/", list); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 503 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 504 | menu.limit(3); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 505 | expect(menu.show()).toBe(undefined); |
| 506 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 507 | expect(menu.element().childNodes[0].innerHTML).toEqual("<strong>Constituency</strong><span>Example 1</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 508 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 509 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Lemma</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 510 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 511 | 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] | 512 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 513 | expect(menu.element().childNodes[3]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 514 | |
| 515 | // Activate prev (1) - roll to bottom |
| 516 | menu.prev(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 517 | expect(menu.element().childNodes[0].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(0).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 519 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 520 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 521 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Syntax</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 522 | expect(menu.shownItem(2).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 523 | expect(menu.element().childNodes[3]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 524 | |
| 525 | // Activate prev (2) |
| 526 | menu.prev(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 527 | expect(menu.element().childNodes[0].innerHTML).toEqual("<strong>Morphology</strong><span>Example 2</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 528 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 529 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Part-of-Speech</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 530 | expect(menu.shownItem(1).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 531 | expect(menu.element().childNodes[2].innerHTML).toEqual("<strong>Syntax</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 532 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 533 | expect(menu.element().childNodes[3]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 534 | |
| 535 | // Activate prev (3) |
| 536 | menu.prev(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 537 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 538 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 539 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 540 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 541 | expect(menu.shownItem(2).name()).toEqual("Syntax"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 542 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 543 | expect(menu.element().childNodes[3]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 544 | |
| 545 | // Activate prev (4) |
| 546 | menu.prev(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 547 | expect(menu.shownItem(0).name()).toEqual("Lemma"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 548 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 549 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 550 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 551 | expect(menu.shownItem(2).name()).toEqual("Part-of-Speech"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 552 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 553 | expect(menu.element().childNodes[3]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 554 | |
| 555 | // Activate prev (5) |
| 556 | menu.prev(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 557 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 558 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 559 | expect(menu.shownItem(1).name()).toEqual("Lemma"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 560 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 561 | expect(menu.shownItem(2).name()).toEqual("Morphology"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 562 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 563 | expect(menu.element().childNodes[3]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 564 | |
| 565 | // Activate next (1) |
| 566 | menu.next(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 567 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 568 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 569 | expect(menu.shownItem(1).name()).toEqual("Lemma"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 570 | expect(menu.shownItem(1).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 571 | expect(menu.shownItem(2).name()).toEqual("Morphology"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 572 | expect(menu.shownItem(2).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 573 | expect(menu.element().childNodes[3]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 574 | |
| 575 | // Activate prev (6) |
| 576 | menu.prev(); |
| 577 | |
| 578 | // Activate prev (7) |
| 579 | menu.prev(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 580 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 581 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 582 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 583 | expect(menu.shownItem(1).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 584 | expect(menu.shownItem(2).name()).toEqual("Syntax"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 585 | expect(menu.shownItem(2).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 586 | expect(menu.element().childNodes[3]).toBe(undefined); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 587 | }); |
| 588 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 589 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 590 | it('should be navigatable and filterable (prefix = "o")', function () { |
| 591 | var menu = KorAP.HintMenu.create("cnx/", list); |
| 592 | menu.limit(2); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 593 | |
| 594 | expect(menu.show("o")).toBe(undefined); |
| 595 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 596 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
| 597 | expect(menu.element().childNodes[0].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] | 598 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 599 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
| 600 | 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] | 601 | expect(menu.shownItem(1).active()).toBe(false); |
| 602 | expect(menu.shownItem(2)).toBe(undefined); |
| 603 | |
| 604 | // Next (1) |
| 605 | menu.next(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 606 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
| 607 | expect(menu.element().childNodes[0].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] | 608 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 609 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
| 610 | 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] | 611 | expect(menu.shownItem(1).active()).toBe(true); |
| 612 | expect(menu.shownItem(2)).toBe(undefined); |
| 613 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 614 | // Next (2) |
| 615 | menu.next(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 616 | expect(menu.shownItem(0).name()).toEqual("Morphology"); |
| 617 | expect(menu.element().childNodes[0].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(0).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 619 | expect(menu.shownItem(1).name()).toEqual("Part-of-Speech"); |
| 620 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Part-<mark>o</mark>f-Speech</strong>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 621 | expect(menu.shownItem(1).active()).toBe(true); |
| 622 | expect(menu.shownItem(2)).toBe(undefined); |
| 623 | |
| 624 | // Next (3) |
| 625 | menu.next(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 626 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
| 627 | expect(menu.element().childNodes[0].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] | 628 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 629 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
| 630 | 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] | 631 | expect(menu.shownItem(1).active()).toBe(false); |
| 632 | expect(menu.shownItem(2)).toBe(undefined); |
| 633 | }); |
| 634 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 635 | |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 636 | it('should be navigatable and filterable (prefix = "ex", "e")', function () { |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 637 | var menu = KorAP.HintMenu.create("cnx/", list); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 638 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 639 | menu.limit(2); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 640 | expect(menu.show("ex")).toBe(undefined); |
| 641 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 642 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
| 643 | expect(menu.element().childNodes[0].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 644 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 645 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
| 646 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 647 | expect(menu.shownItem(1).active()).toBe(false); |
| 648 | expect(menu.shownItem(2)).toBe(undefined); |
| 649 | |
| 650 | // Next (1) |
| 651 | menu.next(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 652 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
| 653 | expect(menu.element().childNodes[0].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 654 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 655 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
| 656 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 657 | expect(menu.shownItem(1).active()).toBe(true); |
| 658 | expect(menu.shownItem(2)).toBe(undefined); |
| 659 | |
| 660 | // Next (2) |
| 661 | menu.next(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 662 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
| 663 | expect(menu.element().childNodes[0].innerHTML).toEqual("<strong>Constituency</strong><span><mark>Ex</mark>ample 1</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 664 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 665 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
| 666 | expect(menu.element().childNodes[1].innerHTML).toEqual("<strong>Morphology</strong><span><mark>Ex</mark>ample 2</span>"); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 667 | expect(menu.shownItem(1).active()).toBe(false); |
| 668 | expect(menu.shownItem(2)).toBe(undefined); |
| 669 | |
| 670 | // Reset limit |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 671 | menu.limit(5); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 672 | |
| 673 | // Change show |
| 674 | expect(menu.show("e")).toBe(undefined); |
| 675 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 676 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
| 677 | expect(menu.element().childNodes[0].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] | 678 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 679 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
| 680 | expect(menu.element().childNodes[1].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] | 681 | expect(menu.shownItem(1).active()).toBe(false); |
| 682 | expect(menu.shownItem(2)).toBe(undefined); |
| 683 | |
| 684 | // Next (1) |
| 685 | menu.next(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 686 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
| 687 | expect(menu.element().childNodes[0].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] | 688 | expect(menu.shownItem(0).active()).toBe(false); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 689 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
| 690 | expect(menu.element().childNodes[1].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] | 691 | expect(menu.shownItem(1).active()).toBe(true); |
| 692 | expect(menu.shownItem(2)).toBe(undefined); |
| 693 | |
| 694 | // Next (2) |
| 695 | menu.next(); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 696 | expect(menu.shownItem(0).name()).toEqual("Constituency"); |
| 697 | expect(menu.element().childNodes[0].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] | 698 | expect(menu.shownItem(0).active()).toBe(true); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame^] | 699 | expect(menu.shownItem(1).name()).toEqual("Morphology"); |
| 700 | expect(menu.element().childNodes[1].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] | 701 | expect(menu.shownItem(1).active()).toBe(false); |
| 702 | expect(menu.shownItem(2)).toBe(undefined); |
| 703 | }); |
| 704 | }); |